#bincode #macro #serde

macro bincode_macro

Add macros to bincode to make it easier to use

3 releases

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

#1536 in Procedural macros

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

~250–700KB
~17K SLoC