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

Write type to bits

  • output - Sink to store resulting bits
  • ctx - A context required by context-sensitive reading. A unit type () means no context needed.

Implementations on Foreign Types

wrapper around u8::write with consideration to context, such as bit size

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])

NOP on write

Write all Ts 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 T from Cow

Write all K, Vs in a HashMap to bits.

  • inner_ctx - The context required by K, V. Note: depending on the Hasher S, the order in which the K, 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 Ts in a HashSet to bits.

  • inner_ctx - The context required by T. Note: depending on the Hasher S, the order in which the T’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])

Write T from box

Write all Ts to bits

Implements DekuWrite for references of types that implement DekuWrite

Write value of type to bits

Implementors