Crates.io | scroll_derive |
lib.rs | scroll_derive |
version | 0.12.0 |
source | src |
created_at | 2017-01-31 06:41:58.184965 |
updated_at | 2024-01-01 00:34:50.345874 |
description | A macros 1.1 derive implementation for Pread and Pwrite traits from the scroll crate |
homepage | |
repository | https://github.com/m4b/scroll |
max_upload_size | |
id | 8320 |
size | 24,086 |
Macros 1.1 implementing #[derive(Pread, Pwrite)] for https://github.com/m4b/scroll
Add derive annotations to your POD seamlessly and easily:
extern crate scroll;
#[macro_use]
extern crate scroll_derive;
#[derive(Debug, PartialEq, Pread, Pwrite, IOread, IOwrite, SizeWith)]
#[repr(C)]
struct Data {
id: u32,
timestamp: f64,
arr: [u16; 2],
}
use scroll::{Pread, Pwrite, Cread, LE};
fn main (){
let bytes = [0xefu8, 0xbe, 0xad, 0xde, 0, 0, 0, 0, 0, 0, 224, 63, 0xad, 0xde, 0xef, 0xbe];
let data: Data = bytes.pread_with(0, LE).unwrap();
println!("data: {data:?}");
assert_eq!(data.id, 0xdeadbeefu32);
let mut bytes2 = vec![0; ::std::mem::size_of::<Data>()];
bytes2.pwrite_with(data, 0, LE).unwrap();
let data: Data = bytes.pread_with(0, LE).unwrap();
let data2: Data = bytes2.pread_with(0, LE).unwrap();
assert_eq!(data, data2);
let data: Data = bytes.cread_with(0, LE);
assert_eq!(data, data2);
}