| Crates.io | binrw |
| lib.rs | binrw |
| version | 0.15.0 |
| created_at | 2020-09-12 03:42:23.595722+00 |
| updated_at | 2025-05-05 21:44:07.797692+00 |
| description | A Rust crate for helping read structs from binary data using ✨macro magic✨ |
| homepage | https://binrw.rs |
| repository | https://github.com/jam1garner/binrw |
| max_upload_size | |
| id | 287618 |
| size | 446,798 |
binrw helps you write maintainable & easy-to-read declarative binary data readers and writers using ✨macro magic✨.
#[derive]io::Read and
io::Write streams#[repr(C)] or
#[repr(packed)])#[derive(BinRead)]
#[br(magic = b"DOG", assert(name.len() != 0))]
struct Dog {
bone_pile_count: u8,
#[br(big, count = bone_pile_count)]
bone_piles: Vec<u16>,
#[br(align_before = 0xA)]
name: NullString
}
let mut reader = Cursor::new(b"DOG\x02\x00\x01\x00\x12\0\0Rudy\0");
let dog: Dog = reader.read_ne().unwrap();
assert_eq!(dog.bone_piles, &[0x1, 0x12]);
assert_eq!(dog.name.into_string(), "Rudy")
For more information, including a more detailed overview of binrw, visit the documentation.