3 releases

0.1.2 Jul 9, 2023
0.1.1 Jul 9, 2023
0.1.0 Jul 9, 2023

#791 in Procedural macros

37 downloads per month

MIT license

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

~320–770KB
~18K SLoC