BoolAdapter

Struct BoolAdapter 

Source
pub struct BoolAdapter<Block, T> { /* private fields */ }
Expand description

Adapts a sequence of bools (e.g., &[bool]) to emulate a bit vector.

In particular, this adapter implements Bits, BitsMut, and BitsPush as appropriate. It implement PartialEq<T> for all T: Bits<Block=Block>. It does not, however, implement slicing, so slice before you adapt.

Note that a bare Vec<bool> or &[bool] already implements Bits, etc., with a Block type of u8. This means that it is only compatible with other u8-based bit vectors. BoolAdapter is instead parametrized by the block type, so it works with bit vectors, slices, and adapters of any uniform block type.

Implementations§

Source§

impl<Block: BlockType, T> BoolAdapter<Block, T>

Source

pub fn new(bits: T) -> Self

Creates a new BoolAdapter from an underlying sequence of bools.

Note that the BoolAdapter derefs to the underlying bool sequence.

§Examples
use nostd_bv::BitSliceable;
use nostd_bv::adapter::BoolAdapter;

let array = [0b101usize];
let bv1 = BoolAdapter::new(vec![true, false, true]);
let bv2 = array.bit_slice(0..3);
assert_eq!( bv1, bv2 );
Source

pub fn into_inner(self) -> T

Gets the underlying bool sequence object back out of a BoolAdapter.

Trait Implementations§

Source§

impl<'a, Block: BlockType> Bits for BoolAdapter<Block, &'a [bool]>

Source§

type Block = Block

The underlying block type used to store the bits of the vector.
Source§

fn bit_len(&self) -> u64

The length of the slice in bits.
Source§

fn get_bit(&self, position: u64) -> bool

Gets the bit at position Read more
Source§

fn block_len(&self) -> usize

The length of the slice in blocks.
Source§

fn get_block(&self, position: usize) -> Self::Block

Gets the block at position, masked as necessary. Read more
Source§

fn get_raw_block(&self, position: usize) -> Self::Block

Gets the block at position, without masking. Read more
Source§

fn get_bits(&self, start: u64, count: usize) -> Self::Block

Gets count bits starting at bit index start, interpreted as a little-endian integer. Read more
Source§

fn to_bit_vec(&self) -> BitVec<Self::Block>

Copies the bits into a new allocated BitVec.
Source§

impl<'a, Block: BlockType> Bits for BoolAdapter<Block, &'a mut [bool]>

Source§

type Block = Block

The underlying block type used to store the bits of the vector.
Source§

fn bit_len(&self) -> u64

The length of the slice in bits.
Source§

fn get_bit(&self, position: u64) -> bool

Gets the bit at position Read more
Source§

fn block_len(&self) -> usize

The length of the slice in blocks.
Source§

fn get_block(&self, position: usize) -> Self::Block

Gets the block at position, masked as necessary. Read more
Source§

fn get_raw_block(&self, position: usize) -> Self::Block

Gets the block at position, without masking. Read more
Source§

fn get_bits(&self, start: u64, count: usize) -> Self::Block

Gets count bits starting at bit index start, interpreted as a little-endian integer. Read more
Source§

fn to_bit_vec(&self) -> BitVec<Self::Block>

Copies the bits into a new allocated BitVec.
Source§

impl<'a, Block: BlockType> Bits for BoolAdapter<Block, &'a mut Vec<bool>>

Source§

type Block = Block

The underlying block type used to store the bits of the vector.
Source§

fn bit_len(&self) -> u64

The length of the slice in bits.
Source§

fn get_bit(&self, position: u64) -> bool

Gets the bit at position Read more
Source§

fn block_len(&self) -> usize

The length of the slice in blocks.
Source§

fn get_block(&self, position: usize) -> Self::Block

Gets the block at position, masked as necessary. Read more
Source§

fn get_raw_block(&self, position: usize) -> Self::Block

Gets the block at position, without masking. Read more
Source§

fn get_bits(&self, start: u64, count: usize) -> Self::Block

Gets count bits starting at bit index start, interpreted as a little-endian integer. Read more
Source§

fn to_bit_vec(&self) -> BitVec<Self::Block>

Copies the bits into a new allocated BitVec.
Source§

impl<Block: BlockType> Bits for BoolAdapter<Block, Vec<bool>>

Source§

type Block = Block

The underlying block type used to store the bits of the vector.
Source§

fn bit_len(&self) -> u64

The length of the slice in bits.
Source§

fn get_bit(&self, position: u64) -> bool

Gets the bit at position Read more
Source§

fn block_len(&self) -> usize

The length of the slice in blocks.
Source§

fn get_block(&self, position: usize) -> Self::Block

Gets the block at position, masked as necessary. Read more
Source§

fn get_raw_block(&self, position: usize) -> Self::Block

Gets the block at position, without masking. Read more
Source§

fn get_bits(&self, start: u64, count: usize) -> Self::Block

Gets count bits starting at bit index start, interpreted as a little-endian integer. Read more
Source§

fn to_bit_vec(&self) -> BitVec<Self::Block>

Copies the bits into a new allocated BitVec.
Source§

impl<'a, Block: BlockType> BitsMut for BoolAdapter<Block, &'a mut [bool]>

Source§

fn set_bit(&mut self, position: u64, value: bool)

Sets the bit at position to value. Read more
Source§

fn set_block(&mut self, position: usize, value: Self::Block)

Sets the block at position to value. Read more
Source§

fn set_bits(&mut self, start: u64, count: usize, value: Self::Block)

Sets count bits starting at bit index start, interpreted as a little-endian integer. Read more
Source§

impl<'a, Block: BlockType> BitsMut for BoolAdapter<Block, &'a mut Vec<bool>>

Source§

fn set_bit(&mut self, position: u64, value: bool)

Sets the bit at position to value. Read more
Source§

fn set_block(&mut self, position: usize, value: Self::Block)

Sets the block at position to value. Read more
Source§

fn set_bits(&mut self, start: u64, count: usize, value: Self::Block)

Sets count bits starting at bit index start, interpreted as a little-endian integer. Read more
Source§

impl<Block: BlockType> BitsMut for BoolAdapter<Block, Vec<bool>>

Source§

fn set_bit(&mut self, position: u64, value: bool)

Sets the bit at position to value. Read more
Source§

fn set_block(&mut self, position: usize, value: Self::Block)

Sets the block at position to value. Read more
Source§

fn set_bits(&mut self, start: u64, count: usize, value: Self::Block)

Sets count bits starting at bit index start, interpreted as a little-endian integer. Read more
Source§

impl<'a, Block: BlockType> BitsPush for BoolAdapter<Block, &'a mut Vec<bool>>

Source§

fn push_bit(&mut self, value: bool)

Adds the given bit to the end of the bit vector.
Source§

fn pop_bit(&mut self) -> Option<bool>

Removes and returns the last bit, if any.
Source§

fn align_block(&mut self, value: bool)

Pushes value 0 or more times until the size of the bit vector is block-aligned.
Source§

fn push_block(&mut self, value: Self::Block)

Pushes the given block onto the end of the bit vector. Read more
Source§

impl<Block: BlockType> BitsPush for BoolAdapter<Block, Vec<bool>>

Source§

fn push_bit(&mut self, value: bool)

Adds the given bit to the end of the bit vector.
Source§

fn pop_bit(&mut self) -> Option<bool>

Removes and returns the last bit, if any.
Source§

fn align_block(&mut self, value: bool)

Pushes value 0 or more times until the size of the bit vector is block-aligned.
Source§

fn push_block(&mut self, value: Self::Block)

Pushes the given block onto the end of the bit vector. Read more
Source§

impl<Block: Clone, T: Clone> Clone for BoolAdapter<Block, T>

Source§

fn clone(&self) -> BoolAdapter<Block, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Block: Debug, T: Debug> Debug for BoolAdapter<Block, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Block, T> Deref for BoolAdapter<Block, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<Block, T> DerefMut for BoolAdapter<Block, T>

Source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
Source§

impl<Block, T, U> PartialEq<U> for BoolAdapter<Block, T>
where Block: BlockType, U: Bits<Block = Block>, Self: Bits<Block = Block>,

Source§

fn eq(&self, other: &U) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<Block, T> Freeze for BoolAdapter<Block, T>
where T: Freeze,

§

impl<Block, T> RefUnwindSafe for BoolAdapter<Block, T>
where T: RefUnwindSafe, Block: RefUnwindSafe,

§

impl<Block, T> Send for BoolAdapter<Block, T>
where T: Send, Block: Send,

§

impl<Block, T> Sync for BoolAdapter<Block, T>
where T: Sync, Block: Sync,

§

impl<Block, T> Unpin for BoolAdapter<Block, T>
where T: Unpin, Block: Unpin,

§

impl<Block, T> UnwindSafe for BoolAdapter<Block, T>
where T: UnwindSafe, Block: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> BitsExt for T
where T: Bits,

Source§

fn bit_concat<Other>(&self, other: Other) -> BitConcat<&Self, Other>
where Other: Bits<Block = Self::Block>,

Concatenates two bit vectors, with the bits of self followed by the bits of other.
Source§

fn into_bit_concat<Other>(self, other: Other) -> BitConcat<Self, Other>
where Self: Sized, Other: Bits<Block = Self::Block>,

Concatenates two bit vectors, with the bits of self followed by the bits of other. Read more
Source§

fn bit_pad(&self, len: u64) -> BitConcat<&Self, BitFill<Self::Block>>

Pads self with 0s on the right to reach at least len bits in length. Read more
Source§

fn into_bit_pad(self, len: u64) -> BitConcat<Self, BitFill<Self::Block>>
where Self: Sized,

Pads self with 0s on the right to reach at least len bits in length. Read more
Source§

fn bit_not(&self) -> BitNot<&Self>

Returns an object that inverts the values of all the bits in self.
Source§

fn into_bit_not(self) -> BitNot<Self>
where Self: Sized,

Returns an object that inverts the values of all the bits in self. Read more
Source§

fn bit_and<Other>(&self, other: Other) -> BitAnd<&Self, Other>
where Other: Bits<Block = Self::Block>,

Returns an object that lazily computes the bit-wise conjunction of two bit-vector-likes. Read more
Source§

fn into_bit_and<Other>(self, other: Other) -> BitAnd<Self, Other>
where Self: Sized, Other: Bits<Block = Self::Block>,

Returns an object that lazily computes the bit-wise conjunction of two bit-vector-likes. Read more
Source§

fn bit_or<Other>(&self, other: Other) -> BitOr<&Self, Other>
where Other: Bits<Block = Self::Block>,

Returns an object that lazily computes the bit-wise disjunction of two bit-vector-likes. Read more
Source§

fn into_bit_or<Other>(self, other: Other) -> BitOr<Self, Other>
where Self: Sized, Other: Bits<Block = Self::Block>,

Returns an object that lazily computes the bit-wise disjunction of two bit-vector-likes. Read more
Source§

fn bit_xor<Other>(&self, other: Other) -> BitXor<&Self, Other>
where Other: Bits<Block = Self::Block>,

Returns an object that lazily computes the bit-wise xor of two bit-vector-likes. Read more
Source§

fn into_bit_xor<Other>(self, other: Other) -> BitXor<Self, Other>
where Self: Sized, Other: Bits<Block = Self::Block>,

Returns an object that lazily computes the bit-wise xor of two bit-vector-likes. Read more
Source§

fn bit_zip<Other, F>(&self, other: Other, fun: F) -> BitZip<&Self, Other, F>
where Other: Bits<Block = Self::Block>, F: Fn(Self::Block, Self::Block, usize) -> Self::Block,

Returns an object that lazily zips a function over the blocks of two bit-vector-like. Read more
Source§

fn into_bit_zip<Other, F>(self, other: Other, fun: F) -> BitZip<Self, Other, F>
where Self: Sized, Other: Bits<Block = Self::Block>, F: Fn(Self::Block, Self::Block, usize) -> Self::Block,

Returns an object that lazily zips a function over the blocks of two bit-vector-like. Read more
Source§

impl<T> BitsMutExt for T
where T: BitsMut,

Source§

fn bit_assign<T: Bits<Block = Self::Block>>(&mut self, other: T)

Assigns the bits of other to self. Read more
Source§

fn bit_and_assign<T: Bits<Block = Self::Block>>(&mut self, other: T)

Assigns the bit-wise and of self and other to self. Read more
Source§

fn bit_or_assign<T: Bits<Block = Self::Block>>(&mut self, other: T)

Assigns the bit-wise or of self and other to self. Read more
Source§

fn bit_xor_assign<T: Bits<Block = Self::Block>>(&mut self, other: T)

Assigns the bit-wise xor of self and other to self. Read more
Source§

fn bit_zip_assign<T, F>(&mut self, other: T, fun: F)
where T: Bits<Block = Self::Block>, F: FnMut(Self::Block, Self::Block) -> Self::Block,

Performs an op-assignment from other to self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.