pub unsafe trait BitArray:
PrimInt
+ Unsigned
+ WrappingAdd
+ WrappingSub
+ WrappingMul
+ LowerHex
+ UpperHex
+ Binary
+ Default
+ Copy
+ Display
+ Debug
+ Eq
+ Hash
+ 'static {
type NonZero: NonZeroBitArray<Base = Self>;
const BITS: usize = _;
// Provided methods
fn into_nonzero(self) -> Option<Self::NonZero> { ... }
unsafe fn into_nonzero_unchecked(self) -> Self::NonZero { ... }
}Expand description
A trait for bit strings of fixed (and usually small) length.
Short fixed-length bit strings are fundamental building blocks of efficient entropy coding algorithms. They are currently used for the following purposes:
- to represent the smallest unit of compressed data (see
stream::Code::Word); - to represent probabilities in fixed point arithmetic (see
stream::model::EntropyModel::Probability); and - the internal state of entropy coders (see
stream::Code::State) is typically comprised of one or moreBitArrays, although this is not a requirement.
This trait is implemented on all primitive unsigned integer types. It is not recommended
to implement this trait for custom types since coders will assume, for performance
considerations, that BitArrays can be represented and manipulated efficiently in
hardware.
§Safety
This trait is marked unsafe so that entropy coders may rely on the assumption that all
BitArrays have precisely the same behavior as builtin unsigned integer types, and that
BitArray::BITS has the correct value.
Provided Associated Constants§
Sourceconst BITS: usize = _
const BITS: usize = _
The (fixed) length of the BitArray in bits.
Defaults to 8 * core::mem::size_of::<Self>(), which is suitable for all
primitive unsigned integers.
This could arguably be called LEN instead, but that may be confusing since
“lengths” are typically not measured in bits in the Rust ecosystem.
Required Associated Types§
type NonZero: NonZeroBitArray<Base = Self>
Provided Methods§
fn into_nonzero(self) -> Option<Self::NonZero>
Sourceunsafe fn into_nonzero_unchecked(self) -> Self::NonZero
unsafe fn into_nonzero_unchecked(self) -> Self::NonZero
§Safety
The provided value must be nonzero.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.