Structure
Use format strings to create strongly-typed data pack/unpack interfaces (inspired by Python's struct library).
Installation
Add this to your Cargo.toml:
[]
= "0.1"
And this to your crate root:
extern crate structure;
Examples
// Two `u32` and one `u8`
let s = structure!;
let buf: = s.pack?;
assert_eq!;
assert_eq!;
It's useful to use pack_into and unpack_from when using types that implement Write or Read.
The following example shows how to send a u32 and a u8 through sockets:
use ;
let listener = bind?;
let mut client = connect?;
let = listener.accept?;
let s = structure!;
s.pack_into?;
let = s.unpack_from?;
assert_eq!;
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.