bincode_macro

Crates.iobincode_macro
lib.rsbincode_macro
version0.1.2
sourcesrc
created_at2023-07-09 13:15:14.258583
updated_at2023-07-09 13:33:39.289811
descriptionAdd macros to bincode to make it easier to use
homepage
repositoryhttps://github.com/felicityin/bincode-macro
max_upload_size
id912057
size4,063
Felicity Yin (felicityin)

documentation

README

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);
}
Commit count: 6

cargo fmt