Trait fibonacci_codec::Encode[][src]

pub trait Encode<T> where
    Self: Sized + Debug + Send + Sync,
    T: Debug + Send + Sync
{ fn fib_encode_mut(
        self,
        vec: &mut BitVec
    ) -> Result<(), ElementEncodeError<T>>; fn fib_encode(self) -> Result<BitVec, ElementEncodeError<T>> { ... } }

Allows encoding enumerations of unsigned integers (> 0) using fibonacci coding.

This crate implements this trait for anything that is IntoIterator with primitive unsigned integer elements.

A note about zero

The number 0 can’t be encoded using fibonacci coding. If you need to encode a zero, you can use .map(|x| x+1) before encoding and invert this when decoding.

Required methods

fn fib_encode_mut(self, vec: &mut BitVec) -> Result<(), ElementEncodeError<T>>[src]

Fibonacci-encodes an iterator yielding integers onto the end of an existing bit vector, until the iterator is exhausted. It extends the bit vector by the number of bits required to hold the entire output.

Error handling

When encountering an encoding error at any element, fib_encode_mut returns an error indicating at which element the error occurred. It leaves the previous, correctly-encoded values’ bits in the result bit vector.

Loading content...

Provided methods

fn fib_encode(self) -> Result<BitVec, ElementEncodeError<T>>[src]

Fibonacci-encodes an iterator of integers into bits and returns the resulting bit vector.

Loading content...

Implementors

impl<T> Encode<u8> for T where
    T: IntoIterator<Item = u8> + Debug + Send + Sync
[src]

impl<T> Encode<u16> for T where
    T: IntoIterator<Item = u16> + Debug + Send + Sync
[src]

impl<T> Encode<u32> for T where
    T: IntoIterator<Item = u32> + Debug + Send + Sync
[src]

impl<T> Encode<u64> for T where
    T: IntoIterator<Item = u64> + Debug + Send + Sync
[src]

Loading content...