2 releases

0.2.1 Jun 4, 2019
0.2.0 Jun 4, 2019

#8 in #eos


Used in eosio_bytes

MIT/Apache

15KB
280 lines

This crate provides three derive macros for eosio_bytes traits.

Examples

use eosio_bytes::{Read, Write, NumBytes};

#[derive(Read, Write, NumBytes, PartialEq, Debug)]
struct Thing(u8);

let thing = Thing(30);

// Number of bytes
assert_eq!(thing.num_bytes(), 1);

// Read bytes
assert_eq!(thing, Thing::read(&mut [30_u8], &mut 0).unwrap());

// Write bytes
let mut bytes = vec![0_u8; 1];
thing.write(&mut bytes, &mut 0).unwrap();
assert_eq!(vec![30], bytes);

lib.rs:

This crate provides three derive macros for eosio_bytes traits.

Examples

use eosio_bytes::{Read, Write, NumBytes};

#[derive(Read, Write, NumBytes, PartialEq, Debug)]
struct Thing(u8);

let thing = Thing(30);

// Number of bytes
assert_eq!(thing.num_bytes(), 1);

// Read bytes
assert_eq!(thing, Thing::read(&mut [30_u8], &mut 0).unwrap());

// Write bytes
let mut bytes = vec![0_u8; 1];
thing.write(&mut bytes, &mut 0).unwrap();
assert_eq!(vec![30], bytes);

Dependencies

~2MB
~47K SLoC