#macro-derive #macro #derive #pread #pwrite #byte

macro scroll_derive

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

21 unstable releases

0.12.0 Jan 1, 2024
0.11.1 Jun 19, 2023
0.11.0 Jan 2, 2022
0.10.5 Jan 25, 2021
0.3.0 Mar 15, 2017

#5 in #pread

Download history 142756/week @ 2024-02-27 148403/week @ 2024-03-05 125306/week @ 2024-03-12 141615/week @ 2024-03-19 123935/week @ 2024-03-26 185569/week @ 2024-04-02 133150/week @ 2024-04-09 149976/week @ 2024-04-16 149970/week @ 2024-04-23 134995/week @ 2024-04-30 139298/week @ 2024-05-07 154795/week @ 2024-05-14 141745/week @ 2024-05-21 163270/week @ 2024-05-28 150352/week @ 2024-06-04 124557/week @ 2024-06-11

603,273 downloads per month
Used in 81 crates (7 directly)

MIT license

22KB
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

~305–760KB
~18K SLoC