-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccd0684
commit 2fc4648
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# binwrite | ||
|
||
A Rust crate for helping write structs as binary data using ✨macro magic✨ | ||
|
||
|
||
## Usage | ||
|
||
The idea behind binwrite is using a derive macro for declaratively defining binary writing. | ||
|
||
### Basic Example | ||
|
||
```rust | ||
use binwrite::BinWrite; | ||
|
||
#[derive(BinWrite)] | ||
struct Point { | ||
x: i32, | ||
y: i32, | ||
} | ||
|
||
fn main() { | ||
let point = Point { x: 1, y: -2 }; | ||
let mut bytes = vec![]; | ||
point.write(&mut bytes).unwrap(); | ||
|
||
assert_eq!(bytes, vec![1, 0, 0, 0, 0xFE, 0xFF, 0xFF, 0xFF]); | ||
} | ||
``` |