Crates.io | eosio_bytes_derive |
lib.rs | eosio_bytes_derive |
version | 0.2.1 |
source | src |
created_at | 2019-06-04 20:54:10.354065 |
updated_at | 2019-06-04 20:55:13.610177 |
description | Macros for automatically deriving EOSIO byte traits. |
homepage | https://sagan-software.github.io/eosio-rust/ |
repository | https://github.com/sagan-software/eosio-rust |
max_upload_size | |
id | 139015 |
size | 26,579 |
This crate provides three derive macros for [eosio_bytes
] traits.
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);