Struct const_base::errors::ExcessBits
source · pub struct ExcessBits { /* private fields */ }
Expand description
When the last byte in the slice passed to decode
has excess set bits that aren’t copied to the return value.
Example
use const_base::{Config, DecodeError, decode};
assert_eq!(decode::<2>(b"ABA", Config::B64).unwrap(), [0u8, 16]);
// base 64 inputs of length 3 are 18 bits, which is 2 bytes and 2 excess bits.
// `ABC` is base64 for `[0b00000000, 0b00010000]` with excess `0b10` bits.
//
// Because the two unused bits at the end (which are `10`) include a set bit,
// it causes the `ExcessBits` error.
match decode::<2>(b"ABC", Config::B64) {
Err(DecodeError::ExcessBits(err)) => {
assert_eq!(err.last_byte(), b'C');
}
_ => unreachable!()
}