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

The bitvector type.

Implementations

Creates an empty BitVec.

Examples
use std::collections::BitVec;
let mut bv = BitVec::new();

Count the number of ones for the bits up to but not including the bitth bit.

Find the index of the nth (0-indexed) set bit.

Creates a BitVec that holds nbits elements, setting each element to bit.

Examples
use std::collections::BitVec;

let mut bv = BitVec::from_elem(10, false);
assert_eq!(bv.len(), 10);
for x in bv.iter() {
    assert_eq!(x, false);
}

Retrieves the value at index i, or None if the index is out of bounds.

Examples
use std::collections::BitVec;

let bv = BitVec::from_bytes(&[0b01100000]);
assert_eq!(bv.get(0), Some(false));
assert_eq!(bv.get(1), Some(true));
assert_eq!(bv.get(100), None);

// Can also use array indexing
assert_eq!(bv[1], true);

Sets the value of a bit at an index i.

Panics

Panics if i is out of bounds.

Examples
use std::collections::BitVec;

let mut bv = BitVec::from_elem(5, false);
bv.set(3, true);
assert_eq!(bv[3], true);

Sets all bits to 1.

Examples
use std::collections::BitVec;

let before = 0b01100000;
let after  = 0b11111111;

let mut bv = BitVec::from_bytes(&[before]);
bv.set_all();
assert_eq!(bv, BitVec::from_bytes(&[after]));

Returns an iterator over the elements of the vector in order.

Examples
use std::collections::BitVec;

let bv = BitVec::from_bytes(&[0b01110100, 0b10010010]);
assert_eq!(bv.iter().filter(|x| *x).count(), 7);

Returns the total number of bits in this vector

Returns true if there are no bits in this vector

Clears all bits in this vector.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The returned type after indexing.

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.