Typed I/O
Typed I/O extends and types std::io
to make it easier to use.
typed_io
contains a number of common things you’ll need when doing input and output. The most core part of this module is the TypedRead and TypedWrite traits, which provide the most general interface for reading and writing input and output with type that easy to handle.
Motivation
The motivation for creating this was that I wanted to process the type as it was.
With std::io
alone, you have to write a few clichéd statements as follows.
use Read;
let mut reader: & = &;
let mut buf = ;
reader.read_exact.unwrap;
let which_i_want = u16 from_le_bytes;
assert_eq!;
I therefore decided to cover them up.
use TypedRead;
let mut reader: & = &;
let which_i_want: u16 = reader.read_le.unwrap;
assert_eq!;
As a side effect, it also hides the raw data [u8]
and allows it to be processed in a typed state.
Getting Started
Installation
This crate works with Cargo and is on crates.io.
Add it to your Cargo.toml
like so:
[]
= "0.1"
If you want to augment existing Read
and Write
traits, then import the extension methods like so:
use ;
Examples
Typed Read
use Cursor;
use TypedRead;
let mut reader = new;
assert_eq!;
assert_eq!;
Typed Write
use TypedWrite;
let mut writer = Vec new;
writer.write_le.unwrap;
writer.write_be.unwrap;
assert_eq!;