Struct bitvec_rs::BitVec

source ·
pub struct BitVec { /* private fields */ }
Expand description

Bit vector with guaranteed [u8] LSB 0 representation and safe mutable access to this slice. Slices into the bit vector are guaranteed to have the unused bits on the last byte set to 0.

Implementations§

source§

impl BitVec

source

pub const fn new() -> Self

Constructs an empty BitVec.

source

pub fn with_capacity(capacity: usize) -> Self

Constructs an empty BitVec with the given capacity.

The bit vector will be able to hold at least capacity bits without reallocating. If capacity is 0, the bit vector will not allocate.

source

pub fn from_bytes(bytes: &[u8]) -> Self

Constructs a BitVec from bytes.

source

pub fn from_bools(bools: &[bool]) -> Self

Constructs a BitVec from bools.

source

pub fn from_elem(len: usize, value: bool) -> Self

Constructs a BitVec from a repeating bit value.

source§

impl BitVec

source

pub fn as_bytes(&self) -> &[u8]

Returns a byte slice view of the data.

source

pub fn with_bytes_mut<U, F: FnOnce(&mut [u8]) -> U>(&mut self, f: F) -> U

Invokes the given function on a mut byte slice view of the data. After f completes, the trailing unused bits of the last byte are automatically set to 0.

source

pub fn into_bytes(self) -> Vec<u8>

Consumes the self and returns the underlying Vec<u8> of length ceil(self.len()/8). The values of the bits in the last byte of Vec<u8> beyond the length of the BitVec are 0.

source

pub fn len(&self) -> usize

Returns the length of the bit vector.

source

pub fn is_empty(&self) -> bool

Returns whether the vector is empty.

source

pub fn get(&self, index: usize) -> Option<bool>

Gets the bit at the given index.

source

pub fn set(&mut self, index: usize, value: bool)

Sets the bit at the given index. Panics if index exceeds length.

source

pub fn swap(&mut self, i: usize, j: usize)

Swaps two elements in the BitVec.

source

pub unsafe fn get_unchecked(&self, index: usize) -> bool

Gets the bit at the given index without bounds checking.

source

pub unsafe fn set_unchecked(&mut self, index: usize, value: bool)

Sets the bit at the given index without bounds checking.

source

pub fn push(&mut self, value: bool)

Pushes a boolean to the end of the BitVec.

source

pub fn pop(&mut self) -> Option<bool>

Pops a boolean from the end of the BitVec.

source

pub fn clear(&mut self)

Clears the BitVec, removing all values.

source

pub fn capacity(&self) -> usize

Returns the number of booleans that the bitvec can hold without reallocating.

source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more booleans to be inserted in the given BitVec. The collection may reserve more space to avoid frequent reallocations.

source

pub fn truncate(&mut self, len: usize)

Shorten a vector, dropping excess elements.

If len is greater than the vector’s current length, this has no effect.

source

pub fn resize(&mut self, new_len: usize, value: bool)

Reserves capacity for at least additional more booleans to be inserted in the given BitVec. The collection may reserve more space to avoid frequent reallocations.

source

pub fn iter(&self) -> Iter<'_>

Returns an iterator for the booleans in the bitvec.

Trait Implementations§

source§

impl Clone for BitVec

source§

fn clone(&self) -> BitVec

Returns a copy 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 Debug for BitVec

source§

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

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

impl Default for BitVec

source§

fn default() -> BitVec

Returns the “default value” for a type. Read more
source§

impl Display for BitVec

source§

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

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

impl<'a> Extend<&'a bool> for BitVec

source§

fn extend<T>(&mut self, iterable: T)where T: IntoIterator<Item = &'a bool>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<bool> for BitVec

source§

fn extend<T>(&mut self, iterable: T)where T: IntoIterator<Item = bool>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl From<&[bool]> for BitVec

source§

fn from(bools: &[bool]) -> Self

Converts to this type from the input type.
source§

impl From<&Vec<bool, Global>> for BitVec

source§

fn from(bools: &Vec<bool>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<bool, Global>> for BitVec

source§

fn from(bools: Vec<bool>) -> Self

Converts to this type from the input type.
source§

impl<'a> FromIterator<&'a bool> for BitVec

source§

fn from_iter<T>(iterable: T) -> Selfwhere T: IntoIterator<Item = &'a bool>,

Creates a value from an iterator. Read more
source§

impl FromIterator<bool> for BitVec

source§

fn from_iter<T>(iterable: T) -> Selfwhere T: IntoIterator<Item = bool>,

Creates a value from an iterator. Read more
source§

impl Index<usize> for BitVec

§

type Output = bool

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<'a> IntoIterator for &'a BitVec

§

type Item = bool

The type of the elements being iterated over.
§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for BitVec

§

type Item = bool

The type of the elements being iterated over.
§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq<BitVec> for BitVec

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for BitVec

source§

impl StructuralEq for BitVec

source§

impl StructuralPartialEq for BitVec

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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<T> ToOwned for Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.