Crates.io | bincode_macro |
lib.rs | bincode_macro |
version | 0.1.2 |
source | src |
created_at | 2023-07-09 13:15:14.258583 |
updated_at | 2023-07-09 13:33:39.289811 |
description | Add macros to bincode to make it easier to use |
homepage | |
repository | https://github.com/felicityin/bincode-macro |
max_upload_size | |
id | 912057 |
size | 4,063 |
Add macro Serde
to bincode to make it easier to use.
cargo add bincode_macro
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);
}