bytestream
This crate provides a convenient way of reading and writing bytes to a buffer
that implements the standard Read
or Write
traits.
Supported std types include u8
, u16
, u32
, u64
, i8
,
i16
, i32
, i64
, String
, Vec<T>
and HashMap<T, V>
.
Reading and writing of these types is done using the byteorder
crate.
Installation
Add the following to your Cargo.toml
file:
[]
= "0.*"
Documentation
You can find the documentation at: https://docs.rs/bytestream
Examples
use ;
use *;
// Create a buffer that implements the `Write` trait
let mut buffer = Vec:: new;
// Write some data to the buffer
let foo = Foo ;
foo.write_to.unwrap;
// Read the data back from the buffer
// We wrap the buffer in a Cursor::<T> that implements the `Read` trait
let mut cursor = new;
let other = read_from.unwrap;
assert_eq!;
Exclude Streamable
support for std types
If you do not wish to include out-of-the-box support for std types,
you can exclude the default batteries-included
feature in your
Cargo.toml
file:
[]
= { = "0.*", = false }
Exluding the batteries-included
feature will also remove
the byteorder
crate dependency.
Credits
The inspiration from this crate came from the Stevenarella
Minecraft client.