bitvec::view

Trait BitView

Source
pub trait BitView {
    type Store: BitStore;

    // Required methods
    fn view_bits<O>(&self) -> &BitSlice<Self::Store, O>
       where O: BitOrder;
    fn try_view_bits<O>(
        &self,
    ) -> Result<&BitSlice<Self::Store, O>, BitSpanError<Self::Store>>
       where O: BitOrder;
    fn view_bits_mut<O>(&mut self) -> &mut BitSlice<Self::Store, O>
       where O: BitOrder;
    fn try_view_bits_mut<O>(
        &mut self,
    ) -> Result<&mut BitSlice<Self::Store, O>, BitSpanError<Self::Store>>
       where O: BitOrder;
}
Expand description

§Bit View

This trait describes a region of memory that can be viewed as its constituent bits. It is blanket-implemented on all BitStore implementors, as well as slices and arrays of them. It should not be implemented on any other types.

The contained extension methods allow existing memory to be easily viewd as BitSlices using dot-call method syntax rather than the more cumbersome constructor functions in BitSlice’s inherent API.

Since the element type is already known to the implementor, the only type parameter you need to provide when calling these methods is the bit-ordering.

§Examples

use bitvec::prelude::*;

let a = 0u16;
let a_bits: &BitSlice<u16, Lsb0> = a.view_bits::<Lsb0>();

let mut b = [0u8; 4];
let b_bits: &mut BitSlice<u8, Msb0> = b.view_bits_mut::<Msb0>();

Required Associated Types§

Source

type Store: BitStore

The underlying element type.

Required Methods§

Source

fn view_bits<O>(&self) -> &BitSlice<Self::Store, O>
where O: BitOrder,

Views a memory region as an immutable bit-slice.

Source

fn try_view_bits<O>( &self, ) -> Result<&BitSlice<Self::Store, O>, BitSpanError<Self::Store>>
where O: BitOrder,

Attempts to view a memory region as an immutable bit-slice.

This may return an error if self is too long to view as a bit-slice.

Source

fn view_bits_mut<O>(&mut self) -> &mut BitSlice<Self::Store, O>
where O: BitOrder,

Views a memory region as a mutable bit-slice.

Source

fn try_view_bits_mut<O>( &mut self, ) -> Result<&mut BitSlice<Self::Store, O>, BitSpanError<Self::Store>>
where O: BitOrder,

Attempts to view a memory region as a mutable bit-slice.

This may return an error if self is too long to view as a bit-slice.

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.

Implementations on Foreign Types§

Source§

impl<T> BitView for [T]
where T: BitStore,

Note that overly-large slices may cause the conversions to fail.

Source§

type Store = T

Source§

fn view_bits<O>(&self) -> &BitSlice<T, O>
where O: BitOrder,

Source§

fn try_view_bits<O>(&self) -> Result<&BitSlice<T, O>, BitSpanError<T>>
where O: BitOrder,

Source§

fn view_bits_mut<O>(&mut self) -> &mut BitSlice<T, O>
where O: BitOrder,

Source§

fn try_view_bits_mut<O>( &mut self, ) -> Result<&mut BitSlice<T, O>, BitSpanError<T>>
where O: BitOrder,

Source§

impl<T, const N: usize> BitView for [T; N]
where T: BitStore,

Note that overly-large arrays may cause the conversions to fail.

Source§

type Store = T

Source§

fn view_bits<O>(&self) -> &BitSlice<T, O>
where O: BitOrder,

Source§

fn try_view_bits<O>(&self) -> Result<&BitSlice<T, O>, BitSpanError<T>>
where O: BitOrder,

Source§

fn view_bits_mut<O>(&mut self) -> &mut BitSlice<T, O>
where O: BitOrder,

Source§

fn try_view_bits_mut<O>( &mut self, ) -> Result<&mut BitSlice<T, O>, BitSpanError<T>>
where O: BitOrder,

Implementors§

Source§

impl<T> BitView for T
where T: BitStore,

Source§

type Store = T