#derive #macros #pread #pwrite #bytes

scroll_derive

A macros 1.1 derive implementation for Pread and Pwrite traits from the scroll crate

18 releases

0.10.5 Jan 25, 2021
0.10.4 Oct 23, 2020
0.10.2 May 9, 2020
0.10.1 Oct 24, 2019
0.3.0 Mar 15, 2017

#23 in Procedural macros

Download history 33294/week @ 2021-06-06 40162/week @ 2021-06-13 39343/week @ 2021-06-20 32825/week @ 2021-06-27 33639/week @ 2021-07-04 31648/week @ 2021-07-11 28663/week @ 2021-07-18 41499/week @ 2021-07-25 31873/week @ 2021-08-01 40074/week @ 2021-08-08 40987/week @ 2021-08-15 58917/week @ 2021-08-22 44890/week @ 2021-08-29 38900/week @ 2021-09-05 37265/week @ 2021-09-12 34420/week @ 2021-09-19

99,179 downloads per month
Used in 31 crates (6 directly)

MIT license

21KB
507 lines

scroll_derive

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);
}

Dependencies

~310–730KB
~18K SLoC