Trait deku::DekuWrite [−][src]
pub trait DekuWrite<Ctx = ()> {
fn write(
&self,
output: &mut BitVec<Msb0, u8>,
ctx: Ctx
) -> Result<(), DekuError>;
}
Expand description
“Writer” trait: write from type to bits
Required methods
Implementations on Foreign Types
Write T if Some
- inner_ctx - The context required by
T
.
Examples
let data = Some(1u8);
let mut output = bitvec![Msb0, u8;];
data.write(&mut output, Endian::Big).unwrap();
assert_eq!(output, bitvec![Msb0, u8; 0, 0, 0, 0, 0, 0, 0, 1])
Write all T
s in a Vec
to bits.
- inner_ctx - The context required by
T
.
Examples
let data = vec![1u8];
let mut output = bitvec![Msb0, u8;];
data.write(&mut output, Endian::Big).unwrap();
assert_eq!(output, bitvec![Msb0, u8; 0, 0, 0, 0, 0, 0, 0, 1])
Write all K, V
s in a HashMap
to bits.
- inner_ctx - The context required by
K, V
. Note: depending on the HasherS
, the order in which theK, V
pairs are written may change between executions. Use a deterministic Hasher for your HashMap instead of the default RandomState hasher if you don’t want the order written to change.
Examples
let mut output = bitvec![Msb0, u8;];
let mut map = HashMap::<u8, u32>::default();
map.insert(100, 0x04030201);
map.write(&mut output, Endian::Big).unwrap();
let expected: Vec<u8> = vec![100, 4, 3, 2, 1];
assert_eq!(expected, output.into_vec())
Write all T
s in a HashSet
to bits.
- inner_ctx - The context required by
T
. Note: depending on the HasherS
, the order in which theT
’s are written may change between executions. Use a deterministic Hasher for your HashSet instead of the default RandomState hasher if you don’t want the order written to change.
Examples
let set: HashSet<u8> = vec![1].into_iter().collect();
let mut output = bitvec![Msb0, u8;];
set.write(&mut output, Endian::Big).unwrap();
assert_eq!(output, bitvec![Msb0, u8; 0, 0, 0, 0, 0, 0, 0, 1])
Implements DekuWrite for references of types that implement DekuWrite