Struct BitVec

Source
pub struct BitVec { /* private fields */ }
Expand description

Represents a vector of bits.

Stores bits using u8 blocks for efficient storage.

Implementations§

Source§

impl BitVec

Source

pub fn new() -> Self

Creates a new, empty BitVec.

Source

pub fn with_capacity(size: usize) -> Self

Creates a new BitVec with the specified capacity in bits.

Source

pub fn zeroes(size: usize) -> Self

Creates a new BitVec with size bits, all initialized to zero.

Source

pub fn ones(size: usize) -> Self

Creates a new BitVec with size bits, all initialized to one.

Source

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

Creates a new BitVec from a slice of booleans.

Source

pub fn len(&self) -> usize

Returns the number of bits in the vector.

Source

pub fn is_empty(&self) -> bool

Returns true if the vector contains no bits.

Source

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

Appends a bit to the end of the vector.

Source

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

Removes the last bit from the vector and returns it.

Returns None if the vector is empty.

Source

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

Gets the value of the bit at index (true if 1, false if 0).

Returns None if the index is out of bounds.

Source

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

Gets the value of the bit at the specified index without bounds checking.

§Safety

Caller must ensure index is less than the length of the BitVec.

Source

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

Sets the bit at index to 1.

§Panics

Panics if index is out of bounds.

Source

pub fn clear(&mut self, index: usize)

Sets the bit at index to 0.

§Panics

Panics if index is out of bounds.

Source

pub fn toggle(&mut self, index: usize)

Flips the bit at index.

§Panics

Panics if index is out of bounds.

Source

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

Sets the bit at index to the specified value.

§Panics

Panics if index is out of bounds.

Source

pub fn clear_all(&mut self)

Sets all bits to 0.

Source

pub fn set_all(&mut self)

Sets all bits to 1.

Source

pub fn count_ones(&self) -> usize

Returns the number of bits set to 1.

Source

pub fn count_zeros(&self) -> usize

Returns the number of bits set to 0.

Source

pub fn and(&mut self, other: &BitVec)

Performs a bitwise AND with another BitVec.

§Panics

Panics if the lengths don’t match.

Source

pub fn or(&mut self, other: &BitVec)

Performs a bitwise OR with another BitVec.

§Panics

Panics if the lengths don’t match.

Source

pub fn xor(&mut self, other: &BitVec)

Performs a bitwise XOR with another BitVec.

§Panics

Panics if the lengths don’t match.

Source

pub fn invert(&mut self)

Flips all bits (1s become 0s and vice versa).

Source

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

Creates an iterator over the bits.

Trait Implementations§

Source§

impl BitAnd for &BitVec

Source§

type Output = BitVec

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl BitOr for &BitVec

Source§

type Output = BitVec

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl BitXor for &BitVec

Source§

type Output = BitVec

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl Clone for BitVec

Source§

fn clone(&self) -> BitVec

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 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() -> Self

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

impl EncodeSize for BitVec

Source§

fn encode_size(&self) -> usize

Returns the encoded size of this value (in bytes).
Source§

impl From<&[bool]> for BitVec

Source§

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

Converts to this type from the input type.
Source§

impl<const N: usize> From<&[bool; N]> for BitVec

Source§

fn from(arr: &[bool; N]) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<[bool; N]> for BitVec

Source§

fn from(arr: [bool; N]) -> Self

Converts to this type from the input type.
Source§

impl From<BitVec> for Vec<bool>

Source§

fn from(bv: BitVec) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<bool>> for BitVec

Source§

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

Converts to this type from the input type.
Source§

impl Index<usize> for BitVec

Source§

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

Allows accessing bits using the [] operator.

Panics if out of bounds.

Source§

type Output = bool

The returned type after indexing.
Source§

impl PartialEq for BitVec

Source§

fn eq(&self, other: &BitVec) -> 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.
Source§

impl Read for BitVec

Source§

type Cfg = RangeCfg

The Cfg type parameter allows passing configuration during the read process. This is crucial for safely decoding untrusted data, for example, by providing size limits for collections or strings. Read more
Source§

fn read_cfg(buf: &mut impl Buf, range: &Self::Cfg) -> Result<Self, CodecError>

Reads a value from the buffer using the provided configuration cfg. Read more
Source§

impl Write for BitVec

Source§

fn write(&self, buf: &mut impl BufMut)

Writes the binary representation of self to the provided buffer buf. Read more
Source§

impl Eq for BitVec

Source§

impl StructuralPartialEq for BitVec

Auto Trait Implementations§

§

impl Freeze for BitVec

§

impl RefUnwindSafe for BitVec

§

impl Send for BitVec

§

impl Sync for BitVec

§

impl Unpin for BitVec

§

impl UnwindSafe for BitVec

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> 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> Decode for T
where T: Read,

Source§

fn decode_cfg(buf: impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Decodes a value from buf using cfg, ensuring the entire buffer is consumed. Read more
Source§

impl<T> Encode for T
where T: Write + EncodeSize,

Source§

fn encode(&self) -> BytesMut

Encodes self into a new BytesMut buffer. 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<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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Codec for T
where T: Encode + Decode,