codicon
Traits for encoding and decoding.
This crate provides generic traits for encoding and decoding to a
std::io::Read
or std::io::Write
type, respectively.
We often need to express that a type can be encoded or decoded. We also need a way to express the type of the encoding or decoding as well as parameters that may be used for that encoding or decoding. This tiny crate solves this problem.
Examples
Let's say we want u8
to be able to be encoded in a (made up) format Foo
which simply writes the byte without modification. We can express this
encoding as follows:
use *;
;
let mut buf = ;
7u8.encode.unwrap;
assert_eq!;
Note that we used a unit struct because the Foo
encoding doesn't take any
options. But if you wanted to specify encoding options, you could just make
a type with parameters.
Decoding works the same as encoding:
use *;
;
let buf = ;
assert_eq!;
License: Apache-2.0