3 releases
0.1.2 | Jul 9, 2023 |
---|---|
0.1.1 | Jul 9, 2023 |
0.1.0 | Jul 9, 2023 |
#1209 in Procedural macros
3KB
Description
Add macro Serde
to bincode to make it easier to use.
Install
cargo add bincode_macro
Usage
use bincode::{error, Decode, Encode};
use bincode_macro::Serde;
#[derive(Serde, Encode, Decode, PartialEq, Debug)]
pub struct Entity {
pub x: u16,
pub y: u32,
}
fn main() {
let mut entity = Entity { x: 1, y: 4 };
let encoded: Vec<u8> = entity.pack().unwrap();
println!("{:?} {}", encoded, encoded.len());
let (decoded, len): (Entity, usize) = entity.unpack(&encoded).unwrap();
println!("{:?}, {}\n", decoded, len);
}
Dependencies
~285–740KB
~18K SLoC