Expand description
A Rust crate for helping write structs as binary data using ✨macro magic✨
§Example:
use binwrite::BinWrite;
#[derive(BinWrite)]
#[binwrite(little)]
struct Rect {
x: i32,
y: i32,
#[binwrite(big)]
size: (u16, u16),
}
fn main() {
let rects = vec![
Rect { x: 1, y: -2, size: (3, 4) },
Rect { x: 20, y: 4, size: (5, 7) }
];
let mut bytes = vec![];
rects.write(&mut bytes).unwrap();
assert_eq!(
bytes,
vec![
// [ x (little endian) ] [ y (little endian) ] [ size.0 ] [ size.1 ]
0x01, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x00, 0x03, 0x00, 0x04,
0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07,
]
);
}
Modules§
- write_
track - Module for WriteTrack<T>
- writers
- Built-in special writers (example: C strings)
Macros§
- writer_
option_ new - Macro for creating a new writer option, with the idea being a non-verbose means of providing a forwards-compatible set of options which uses default values for all provided options.
Structs§
- Writer
Option - Options on how to write. Use writer_option_new! to create a new instance. Manual initialization is not possible to prevent forward compatibility issues.
Enums§
- Endian
- An enum to represent what endianness to write with
Traits§
- BinWrite
- A trait providing the ability to write the struct to a writer
Derive Macros§
- BinWrite
- Derive macro for BinWrite. Usage here.