serial_traits_derive

Crates.ioserial_traits_derive
lib.rsserial_traits_derive
version1.1.0
created_at2025-12-13 14:36:54.969612+00
updated_at2025-12-14 20:12:33.890029+00
descriptionImplements the derive-macro for serial_traits' Serializable trait!
homepage
repositoryhttps://codeberg.org/Taureon/serial_traits_derive
max_upload_size
id1982973
size28,811
Taureon (Taureon)

documentation

README

serial_traits_derive

Implements the derive-macro for serial_traits' Serializable trait!

How to use

The macro has the same name as the trait, and it is easily applied to structs and enums.

#[derive(Serializable)]
enum TestEnum {
    NoExtras,
    Description (String),
    Details {
        description: String,
        links: HashMap<String, String>
    }
}

#[derive(Serializable)]
struct TestStruct {
    name: String,
    extra: TestEnum,
    tags: Vec<String>,
}

The serialize and parse methods can be used the same.

let test: TestStruct = getTestStructInstanceSomehow();

let mut buffer = test.serialize();

let result = TestStruct::parse(&mut buffer);

// Implementation of Debug and PartialEq assumed for this.
assert_eq!(test, result.unwrap())

Minor Caveats:

  • Booleans are inefficient in some situations.
    • bool/Option<T>/Result<T, E> in inner structs are not optimised for space as efficiently as theoretically possible.
      • Also applies to these three existing in collection types, i.e. Vec<T> or HashMap<K, V>.
    • Option<bool>/Result<bool, bool> would take an extra byte when not necessary.
    • "The more boolean-ish fields you have the less efficient the serialization becomes"
      • It currently does not store the booleans in a series of u8s, but rather either a u8, u16, u32, u64, or u128 depending on the smallest needed.
Commit count: 0

cargo fmt