#derive #macros #pread #pwrite #bytes

macro scroll_derive

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

14 releases (7 breaking)

0.9.5 Sep 22, 2018
0.9.4 May 28, 2018
0.9.3 Apr 22, 2018
0.9.2 Mar 10, 2018
0.3.0 Mar 15, 2017

#35 in Rust patterns

Download history 1024/week @ 2018-10-14 842/week @ 2018-10-21 802/week @ 2018-10-28 918/week @ 2018-11-04 1000/week @ 2018-11-11 1103/week @ 2018-11-18 1263/week @ 2018-11-25 1289/week @ 2018-12-02 1631/week @ 2018-12-09 1419/week @ 2018-12-16 881/week @ 2018-12-23 1182/week @ 2018-12-30 1346/week @ 2019-01-06 1513/week @ 2019-01-13 1666/week @ 2019-01-20

4,717 downloads per month
Used in 5 crates (2 directly)

MIT license

14KB
315 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

~1MB
~18K SLoC