| Crates.io | serial_traits_derive |
| lib.rs | serial_traits_derive |
| version | 1.1.0 |
| created_at | 2025-12-13 14:36:54.969612+00 |
| updated_at | 2025-12-14 20:12:33.890029+00 |
| description | Implements the derive-macro for serial_traits' Serializable trait! |
| homepage | |
| repository | https://codeberg.org/Taureon/serial_traits_derive |
| max_upload_size | |
| id | 1982973 |
| size | 28,811 |
Implements the derive-macro for serial_traits' Serializable trait!
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:
bool/Option<T>/Result<T, E> in inner structs are not optimised for space as efficiently as theoretically possible.
Vec<T> or HashMap<K, V>.Option<bool>/Result<bool, bool> would take an extra byte when not necessary.u8s, but rather either a u8, u16, u32, u64, or u128 depending on the smallest needed.