oxicode_derive

Crates.iooxicode_derive
lib.rsoxicode_derive
version0.1.0
created_at2025-12-28 16:43:18.821829+00
updated_at2025-12-28 16:43:18.821829+00
descriptionDerive macros for oxicode
homepage
repositoryhttps://github.com/cool-japan/oxicode
max_upload_size
id2009125
size16,992
KitaSan (cool-japan)

documentation

README

oxicode_derive

Procedural macros for deriving Encode and Decode traits for the OxiCode binary serialization library.

Overview

This crate provides derive macros that automatically implement the Encode and Decode traits for your custom types. It is part of the OxiCode ecosystem and is typically used through the main oxicode crate with the derive feature enabled.

Usage

Add oxicode to your Cargo.toml with the derive feature:

[dependencies]
oxicode = { version = "0.1", features = ["derive"] }

Then use the derive macros on your types:

use oxicode::{Encode, Decode};

#[derive(Encode, Decode)]
struct Point {
    x: f32,
    y: f32,
}

#[derive(Encode, Decode)]
enum Message {
    Quit,
    Move { x: i32, y: i32 },
    Write(String),
}

Supported Types

The derive macros support:

  • Structs with named fields, unnamed fields (tuple structs), or unit structs
  • Enums with any combination of named, unnamed, and unit variants
  • Generics with full lifetime and type parameter support
  • Where clauses and bounds

Example

use oxicode::{encode, decode, Encode, Decode};

#[derive(Debug, PartialEq, Encode, Decode)]
struct User<'a> {
    id: u64,
    name: &'a str,
    active: bool,
}

#[derive(Debug, PartialEq, Encode, Decode)]
enum Status {
    Active,
    Inactive,
    Pending { reason: String },
}

fn main() -> Result<(), oxicode::Error> {
    let user = User {
        id: 42,
        name: "Alice",
        active: true,
    };

    let bytes = encode(&user)?;
    let decoded: User = decode(&bytes)?;

    assert_eq!(user, decoded);
    Ok(())
}

Features

  • Zero-cost abstractions: Generated code is as efficient as hand-written implementations
  • Generic support: Full support for generic types with automatic trait bounds
  • Lifetime support: Works seamlessly with borrowed data
  • Error handling: Proper error propagation with Result types

Limitations

  • Unions: Derive macros cannot be used on unions due to safety concerns
  • Manual implementations: For complex scenarios, you may need to implement Encode and Decode manually

Documentation

For detailed documentation, see the OxiCode crate documentation.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please see the main repository for contribution guidelines.

Commit count: 0

cargo fmt