referrerpolicy=no-referrer-when-downgrade
polkadot_primitives::v8

Type Alias NodeFeatures

Source
pub type NodeFeatures = BitVec<u8, Lsb0>;
Expand description

Bit indices in the HostConfiguration.node_features that correspond to different node features.

Aliased Type§

struct NodeFeatures { /* private fields */ }

Implementations

§

impl<T, O> BitVec<T, O>
where T: BitStore, O: BitOrder,

Constructors.

pub const EMPTY: BitVec<T, O> = _

An empty bit-vector with no backing allocation.

pub fn repeat(bit: bool, len: usize) -> BitVec<T, O>

Creates a new bit-vector by repeating a bit for the desired length.

§Examples
use bitvec::prelude::*;

let zeros = BitVec::<u8, Msb0>::repeat(false, 50);
let ones = BitVec::<u16, Lsb0>::repeat(true, 50);

pub fn from_bitslice(slice: &BitSlice<T, O>) -> BitVec<T, O>

Copies the contents of a bit-slice into a new heap allocation.

This copies the raw underlying elements into a new allocation, and sets the produced bit-vector to use the same memory layout as the originating bit-slice. This means that it may begin at any bit in the first element, not just the zeroth bit. If you require this property, call .force_align().

Dead bits in the copied memory elements are guaranteed to be zeroed.

§Examples
use bitvec::prelude::*;

let bits = bits![0, 1, 0, 0, 1];
let bv = BitVec::from_bitslice(bits);
assert_eq!(bv, bits);

pub fn from_element(elem: T) -> BitVec<T, O>

Constructs a new bit-vector from a single element.

This copies elem into a new heap allocation, and sets the bit-vector to cover it entirely.

§Examples
use bitvec::prelude::*;

let bv = BitVec::<_, Msb0>::from_element(1u8);
assert!(bv[7]);

pub fn from_slice(slice: &[T]) -> BitVec<T, O>

Constructs a new bit-vector from a slice of memory elements.

This copies slice into a new heap allocation, and sets the bit-vector to cover it entirely.

§Panics

This panics if slice exceeds bit-vector capacity.

§Examples
use bitvec::prelude::*;

let slice = &[0u8, 1, 2, 3];
let bv = BitVec::<_, Lsb0>::from_slice(slice);
assert_eq!(bv.len(), 32);

pub fn try_from_slice(slice: &[T]) -> Result<BitVec<T, O>, BitSpanError<T>>

Fallibly constructs a new bit-vector from a slice of memory elements.

This fails early if slice exceeds bit-vector capacity. If it is not, then slice is copied into a new heap allocation and fully spanned by the returned bit-vector.

§Examples
use bitvec::prelude::*;

let slice = &[0u8, 1, 2, 3];
let bv = BitVec::<_, Lsb0>::try_from_slice(slice).unwrap();
assert_eq!(bv.len(), 32);

pub fn from_vec(vec: Vec<T>) -> BitVec<T, O>

Converts a regular vector in-place into a bit-vector.

The produced bit-vector spans every bit in the original vector. No reällocation occurs; this is purely a transform of the handle.

§Panics

This panics if the source vector is too long to view as a bit-slice.

§Examples
use bitvec::prelude::*;

let v = vec![0u8, 1, 2, 3];
let bv = BitVec::<_, Msb0>::from_vec(v);
assert_eq!(bv.len(), 32);

pub fn try_from_vec(vec: Vec<T>) -> Result<BitVec<T, O>, Vec<T>>

Attempts to convert a regular vector in-place into a bit-vector.

This fails if the source vector is too long to view as a bit-slice. On success, the produced bit-vector spans every bit in the original vector. No reällocation occurs; this is purely a transform of the handle.

§Examples
use bitvec::prelude::*;

let v = vec![0u8; 20];
assert_eq!(BitVec::<_, Msb0>::try_from_vec(v).unwrap().len(), 160);

It is not practical to allocate a vector that will fail this conversion.

pub fn extend_from_bitslice<T2, O2>(&mut self, other: &BitSlice<T2, O2>)
where T2: BitStore, O2: BitOrder,

Appends the contents of a bit-slice to a bit-vector.

This can extend from a bit-slice of any type parameters; it is not restricted to using the same parameters as self. However, when the type parameters do match, it is possible for this to use a batch-copy optimization to go faster than the individual-bit crawl that is necessary when they differ.

Until Rust provides extensive support for specialization in trait implementations, you should use this method whenever you are extending from a BitSlice proper, and only use the general .extend() implementation if you are required to use a generic bool source.

§Original

Vec::extend_from_slice

§Examples
use bitvec::prelude::*;

let mut bv = bitvec![0, 1];
bv.extend_from_bitslice(bits![0, 1, 0, 0, 1]);
assert_eq!(bv, bits![0, 1, 0, 1, 0, 0, 1]);

pub fn extend_from_raw_slice(&mut self, slice: &[T])

Appends a slice of T elements to a bit-vector.

The slice is viewed as a BitSlice<T, O>, then appended directly to the bit-vector.

§Original

Vec::extend_from_slice

§

impl<T, O> BitVec<T, O>
where T: BitStore, O: BitOrder,

Converters.

pub fn as_bitslice(&self) -> &BitSlice<T, O>

Explicitly views the bit-vector as a bit-slice.

pub fn as_mut_bitslice(&mut self) -> &mut BitSlice<T, O>

Explicitly views the bit-vector as a mutable bit-slice.

pub fn as_raw_slice(&self) -> &[T]

Views the bit-vector as a slice of its underlying memory elements.

pub fn as_raw_mut_slice(&mut self) -> &mut [T]

Views the bit-vector as a mutable slice of its underlying memory elements.

pub fn as_bitptr(&self) -> BitPtr<Const, T, O>

Creates an unsafe shared bit-pointer to the start of the buffer.

§Original

Vec::as_ptr

§Safety

You must initialize the contents of the underlying buffer before accessing memory through this pointer. See the BitPtr documentation for more details.

pub fn as_mut_bitptr(&mut self) -> BitPtr<Mut, T, O>

Creates an unsafe writable bit-pointer to the start of the buffer.

§Original

Vec::as_mut_ptr

§Safety

You must initialize the contents of the underlying buffer before accessing memory through this pointer. See the BitPtr documentation for more details.

pub fn into_boxed_bitslice(self) -> BitBox<T, O>

Converts a bit-vector into a boxed bit-slice.

This may cause a reällocation to drop any excess capacity.

§Original

Vec::into_boxed_slice

§Examples
use bitvec::prelude::*;

let bv = bitvec![0, 1, 0, 0, 1];
let bb = bv.into_boxed_bitslice();

pub fn into_vec(self) -> Vec<T>

Converts a bit-vector into a Vec of its underlying storage.

The produced vector contains all elements that contained live bits. Dead bits have an unspecified value; you should call .set_uninitialized() before converting into a vector.

This does not affect the allocated memory; it is purely a conversion of the handle.

§Examples
use bitvec::prelude::*;

let bv = bitvec![u8, Msb0; 0, 1, 0, 0, 1];
let v = bv.into_vec();
assert_eq!(v[0] & 0xF8, 0b01001_000);
§

impl<T, O> BitVec<T, O>
where T: BitStore, O: BitOrder,

Port of the Vec<T> inherent API.

pub fn new() -> BitVec<T, O>

Constructs a new, empty, bit-vector.

This does not allocate until bits are .push()ed into it, or space is explicitly .reserve()d.

§Original

Vec::new

§Examples
use bitvec::prelude::*;

let bv = BitVec::<u8, Msb0>::new();
assert!(bv.is_empty());

pub fn with_capacity(capacity: usize) -> BitVec<T, O>

Allocates a new, empty, bit-vector with space for at least capacity bits before reallocating.

§Original

Vec::with_capacity

§Panics

This panics if the requested capacity is longer than what the bit-vector can represent. See BitSlice::MAX_BITS.

§Examples
use bitvec::prelude::*;

let mut bv: BitVec = BitVec::with_capacity(128);

assert!(bv.is_empty());
assert!(bv.capacity() >= 128);

for i in 0 .. 128 {
  bv.push(i & 0xC0 == i);
}
assert_eq!(bv.len(), 128);
assert!(bv.capacity() >= 128);

bv.push(false);
assert_eq!(bv.len(), 129);
assert!(bv.capacity() >= 129);

pub unsafe fn from_raw_parts( bitptr: BitPtr<Mut, T, O>, length: usize, capacity: usize, ) -> BitVec<T, O>

Constructs a bit-vector handle from its constituent fields.

§Original

Vec::from_raw_parts

§Safety

The only acceptable argument values for this function are those that were previously produced by calling .into_raw_parts(). Furthermore, you may only call this at most once on any set of arguments. Using the same arguments in more than one call to this function will result in a double- or use-after free error.

Attempting to conjure your own values and pass them into this function will break the allocator state.

§Examples
use bitvec::prelude::*;

let bv = bitvec![0, 1, 0, 0, 1];
let (bitptr, len, capa) = bv.into_raw_parts();
let bv2 = unsafe {
  BitVec::from_raw_parts(bitptr, len, capa)
};
assert_eq!(bv2, bits![0, 1, 0, 0, 1]);

pub fn into_raw_parts(self) -> (BitPtr<Mut, T, O>, usize, usize)

Decomposes a bit-vector into its constituent member fields.

This disarms the destructor. In order to prevent a memory leak, you must pass these exact values back into ::from_raw_parts().

§Original

Vec::into_raw_parts

§API Differences

This method is still unstable as of 1.54. It is provided here as a convenience, under the expectation that the standard-library method will stabilize as-is.

pub fn capacity(&self) -> usize

Gets the allocation capacity, measured in bits.

This counts how many total bits the bit-vector can store before it must perform a reällocation to acquire more memory.

If the capacity is not a multiple of 8, you should call .force_align().

§Original

Vec::capacity

§Examples
use bitvec::prelude::*;

let bv = bitvec![0, 1, 0, 0, 1];

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

Ensures that the bit-vector has allocation capacity for at least additional more bits to be appended to it.

For convenience, this method guarantees that the underlying memory for self[.. self.len() + additional] is initialized, and may be safely accessed directly without requiring use of .push() or .extend() to initialize it.

Newly-allocated memory is always initialized to zero. It is still dead until the bit-vector is grown (by .push(), .extend(), or .set_len()), but direct access will not trigger UB.

§Original

Vec::reserve

§Panics

This panics if the new capacity exceeds the bit-vector’s maximum.

§Examples
use bitvec::prelude::*;

let mut bv: BitVec = BitVec::with_capacity(80);
assert!(bv.capacity() >= 80);
bv.reserve(800);
assert!(bv.capacity() >= 800);

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

Ensures that the bit-vector has allocation capacity for at least additional more bits to be appended to it.

This differs from .reserve() by requesting that the allocator provide the minimum capacity necessary, rather than a potentially larger amount that the allocator may find more convenient.

Remember that this is a request: the allocator provides what it provides, and you cannot rely on the new capacity to be exactly minimal. You should still prefer .reserve(), especially if you expect to append to the bit-vector in the future.

§Original

Vec::reserve_exact

§Panics

This panics if the new capacity exceeds the bit-vector’s maximum.

§Examples
use bitvec::prelude::*;

let mut bv: BitVec = BitVec::with_capacity(80);
assert!(bv.capacity() >= 80);
bv.reserve_exact(800);
assert!(bv.capacity() >= 800);

pub fn shrink_to_fit(&mut self)

Releases excess capacity back to the allocator.

Like .reserve_exact(), this is a request to the allocator, not a command. The allocator may reclaim excess memory or may not.

§Original

Vec::shrink_to_fit

§Examples
use bitvec::prelude::*;

let mut bv: BitVec = BitVec::with_capacity(1000);
bv.push(true);
bv.shrink_to_fit();

pub fn into_boxed_slice(self) -> BitBox<T, O>

👎Deprecated: prefer `.into_boxed_bitslice() instead

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

Shortens the bit-vector, keeping the first new_len bits and discarding the rest.

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

The .drain() method can emulate .truncate(), except that it yields the excess bits rather than discarding them.

Note that this has no effect on the allocated capacity of the bit-vector, nor does it erase truncated memory. Bits in the allocated memory that are outside of the .as_bitslice() view are always considered to have initialized, but unspecified, values, and you cannot rely on them to be zero.

§Original

Vec::truncate

§Examples

Truncating a five-bit vector to two bits:

use bitvec::prelude::*;

let mut bv = bitvec![0, 1, 0, 0, 1];
bv.truncate(2);
assert_eq!(bv.len(), 2);
assert!(bv.as_raw_slice()[0].count_ones() >= 2);

No truncation occurs when len is greater than the bit-vector’s current length:

pub fn as_slice(&self) -> &BitSlice<T, O>

👎Deprecated: use .as_bitslice() instead

pub fn as_mut_slice(&mut self) -> &mut BitSlice<T, O>

👎Deprecated: use .as_mut_bitslice() instead

pub fn as_ptr(&self) -> BitPtr<Const, T, O>

👎Deprecated: use .as_bitptr() instead

pub fn as_mut_ptr(&mut self) -> BitPtr<Mut, T, O>

👎Deprecated: use .as_mut_bitptr() instead

pub unsafe fn set_len(&mut self, new_len: usize)

Resizes a bit-vector to a new length.

§Original

Vec::set_len

§Safety

NOT ALL MEMORY IN THE ALLOCATION IS INITIALIZED!

Memory in a bit-vector’s allocation is only initialized when the bit-vector grows into it normally (through .push() or one of the various .extend*() methods). Setting the length to a value beyond what was previously initialized, but still within the allocation, is undefined behavior.

The caller is responsible for ensuring that all memory up to (but not including) the new length has already been initialized.

§Panics

This panics if new_len exceeds the capacity as reported by .capacity().

§Examples
use bitvec::prelude::*;

let mut bv = bitvec![0, 1, 0, 0, 1];
unsafe {
  // The default storage type, `usize`, is at least 32 bits.
  bv.set_len(32);
}
assert_eq!(bv, bits![
  0, 1, 0, 0, 1, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0,
]);
//  `BitVec` guarantees that newly-initialized memory is zeroed.

pub fn swap_remove(&mut self, index: usize) -> bool

Takes a bit out of the bit-vector.

The empty slot is filled with the last bit in the bit-vector, rather than shunting index + 1 .. self.len() down by one.

§Original

Vec::swap_remove

§Panics

This panics if index is out of bounds (self.len() or greater).

§Examples
use bitvec::prelude::*;

let mut bv = bitvec![0, 1, 0, 0, 1];
assert!(!bv.swap_remove(2));
assert_eq!(bv, bits![0, 1, 1, 0]);

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

Inserts a bit at a given position, shifting all bits after it one spot to the right.

index may be any value up to and including self.len(). If it is self.len(), it behaves equivalently to .push().

§Original

Vec::insert

§Panics

This panics if index is out of bounds (including self.len()).

pub fn remove(&mut self, index: usize) -> bool

Removes a bit at a given position, shifting all bits after it one spot to the left.

index may be any value up to, but not including, self.len().

§Original

Vec::remove

§Panics

This panics if index is out of bounds (excluding self.len()).

pub fn retain<F>(&mut self, func: F)
where F: FnMut(usize, &bool) -> bool,

Retains only the bits that the predicate allows.

Bits are deleted from the vector when the predicate function returns false. This function is linear in self.len().

§Original

Vec::retain

§API Differences

The predicate receives both the index of the bit as well as its value, in order to allow the predicate to have more than one bit of keep/discard information.

§Examples
use bitvec::prelude::*;

let mut bv = bitvec![0, 1, 0, 0, 1];
bv.retain(|idx, _| idx % 2 == 0);
assert_eq!(bv, bits![0,    0,    1]);

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

Appends a single bit to the vector.

§Original

Vec::push

§Panics

This panics if the push would cause the bit-vector to exceed its maximum capacity.

§Examples
use bitvec::prelude::*;

let mut bv = bitvec![0, 0];
bv.push(true);
assert_eq!(bv.as_bitslice(), bits![0, 0, 1]);

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

Attempts to remove the trailing bit from the bit-vector.

This returns None if the bit-vector is empty.

§Original

Vec::pop

§Examples
use bitvec::prelude::*;

let mut bv = bitvec![0, 1];
assert!(bv.pop().unwrap());
assert!(!bv.pop().unwrap());
assert!(bv.pop().is_none());

pub fn append<T2, O2>(&mut self, other: &mut BitVec<T2, O2>)
where T2: BitStore, O2: BitOrder,

Moves all the bits out of other into the back of self.

The other bit-vector is emptied after this occurs.

§Original

Vec::append

§API Differences

This permits other to have different type parameters than self, and does not require that it be literally Self.

§Panics

This panics if self.len() + other.len() exceeds the maximum capacity of a bit-vector.

§Examples
use bitvec::prelude::*;

let mut bv1 = bitvec![u16, Msb0; 0; 10];
let mut bv2 = bitvec![u32, Lsb0; 1; 10];

bv1.append(&mut bv2);

assert_eq!(bv1.count_ones(), 10);
assert_eq!(bv1.count_zeros(), 10);
assert!(bv2.is_empty());

pub fn drain<R>(&mut self, range: R) -> Drain<'_, T, O>
where R: RangeBounds<usize>,

Iterates over a portion of the bit-vector, removing all yielded bits from it.

When the iterator drops, all bits in its coverage are removed from self, even if the iterator did not yield them. If the iterator is leaked or otherwise forgotten, and its destructor never runs, then the amount of un-yielded bits removed from the bit-vector is not specified.

§Original

Vec::drain

§Panics

This panics if range departs 0 .. self.len().

§Examples
use bitvec::prelude::*;

let mut bv = bitvec![0, 1, 0, 0, 1];
let bv2 = bv.drain(1 ..= 3).collect::<BitVec>();
assert_eq!(bv, bits![0,          1]);
assert_eq!(bv2, bits![1, 0, 0]);

// A full range clears the bit-vector.
bv.drain(..);
assert!(bv.is_empty());

pub fn clear(&mut self)

Empties the bit-vector.

This does not affect the allocated capacity.

§Original

Vec::clear

§Examples
use bitvec::prelude::*;

let mut bv = bitvec![0, 1, 0, 0, 1];
bv.clear();
assert!(bv.is_empty());

pub fn len(&self) -> usize

Gets the length of the bit-vector.

This is equivalent to BitSlice::len; it is provided as an inherent method here rather than relying on Deref forwarding so that you can write BitVec::len as a named function item.

§Original

Vec::len

pub fn is_empty(&self) -> bool

Tests if the bit-vector is empty.

This is equivalent to BitSlice::is_empty; it is provided as an inherent method here rather than relying on Deref forwarding so that you can write BitVec::is_empty as a named function item.

§Original

Vec::is_empty

pub fn split_off(&mut self, at: usize) -> BitVec<T, O>

Splits the bit-vector in half at an index, moving self[at ..] out into a new bit-vector.

§Original

Vec::split_off

§Examples
use bitvec::prelude::*;

let mut bv = bitvec![0, 1, 0, 0, 1];
let bv2 = bv.split_off(2);
assert_eq!((&*bv, &*bv2), (bits![0, 1], bits![0, 0, 1]));

pub fn resize_with<F>(&mut self, new_len: usize, func: F)
where F: FnMut(usize) -> bool,

Resizes the bit-vector to a new length, using a function to produce each inserted bit.

If new_len is less than self.len(), this is a truncate operation; if it is greater, then self is extended by repeatedly pushing func().

§Original

Vec::resize_with

§API Differences

The generator function receives the index into which its bit will be placed.

§Examples
use bitvec::prelude::*;

let mut bv = bitvec![1; 2];
bv.resize_with(5, |idx| idx % 2 == 1);
assert_eq!(bv, bits![1, 1, 0, 1, 0]);

pub fn leak<'a>(self) -> &'a mut BitSlice<T, O>

Destroys the BitVec handle without destroying the bit-vector allocation. The allocation is returned as an &mut BitSlice that lasts for the remaining program lifetime.

You may call [BitBox::from_raw] on this slice handle exactly once in order to reap the allocation before program exit. That function takes a mutable pointer, not a mutable reference, so you must ensure that the returned reference is never used again after restoring the allocation handle.

§Original

Vec::leak

§Examples
use bitvec::prelude::*;

let bv = bitvec![0, 0, 1];
let static_bits: &'static mut BitSlice = bv.leak();
static_bits.set(0, true);
assert_eq!(static_bits, bits![1, 0, 1]);

let bb = unsafe { BitBox::from_raw(static_bits) };
// static_bits may no longer be used.
drop(bb); // explicitly reap memory before program exit

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

Resizes the bit-vector to a new length. New bits are initialized to value.

§Original

Vec::resize

§Examples
use bitvec::prelude::*;

let mut bv = bitvec![0; 2];
bv.resize(5, true);
assert_eq!(bv, bits![0, 0, 1, 1, 1]);

pub fn extend_from_slice<T2, O2>(&mut self, other: &BitSlice<T2, O2>)
where T2: BitStore, O2: BitOrder,

👎Deprecated: use .extend_from_bitslice() or .extend_from_raw_slice() instead

pub fn extend_from_within<R>(&mut self, src: R)
where R: RangeExt<usize>,

Extends self by copying an internal range of its bit-slice as the region to append.

§Original

Vec::extend_from_within

§Panics

This panics if src is not within 0 .. self.len().

§Examples
use bitvec::prelude::*;

let mut bv = bitvec![0, 1, 0, 0, 1];
bv.extend_from_within(1 .. 4);
assert_eq!(bv, bits![0, 1, 0, 0, 1, 1, 0, 0]);

pub fn splice<R, I>( &mut self, range: R, replace_with: I, ) -> Splice<'_, T, O, <I as IntoIterator>::IntoIter>
where R: RangeBounds<usize>, I: IntoIterator<Item = bool>,

Modifies self.drain() so that the removed bit-slice is instead replaced with the contents of another bit-stream.

As with .drain(), the specified range is always removed from the bit-vector even if the splicer is not fully consumed, and the splicer does not specify how many bits are removed if it leaks.

The replacement source is only consumed when the splicer drops; however, it may be pulled before then. The replacement source cannot assume that there will be a delay between creation of the splicer and when it must begin producing bits.

This copies the Vec::splice implementation; see its documentation for more details about how the replacement should act.

§Original

Vec::splice

§Panics

This panics if range departs 0 .. self.len().

§Examples
use bitvec::prelude::*;

let mut bv = bitvec![0, 1, 1];
//                   a  b  c
let mut yank = bv.splice(
  .. 2,
  bits![static 1, 1, 0].iter().by_vals(),
//             d  e  f
);

assert!(!yank.next().unwrap()); // a
assert!(yank.next().unwrap()); // b
drop(yank);
assert_eq!(bv, bits![1, 1, 0, 1]);
//                   d  e  f  c
§

impl<T, O> BitVec<T, O>
where T: BitStore, O: BitOrder,

Utilities.

pub fn set_elements(&mut self, element: <T as BitStore>::Mem)

Overwrites each element (visible in .as_raw_mut_slice()) with a new bit-pattern.

This unconditionally writes element into each element in the backing slice, without altering the bit-vector’s length or capacity.

This guarantees that dead bits visible in .as_raw_slice() but not .as_bitslice() are initialized according to the bit-pattern of element. The elements not visible in the raw slice, but present in the allocation, do not specify a value. You may not rely on them being zeroed or being set to the element bit-pattern.

§Parameters
  • &mut self
  • element: The bit-pattern with which each live element in the backing store is initialized.
§Examples
use bitvec::prelude::*;

let mut bv = bitvec![u8, Msb0; 0; 20];
assert_eq!(bv.as_raw_slice(), [0; 3]);
bv.set_elements(0xA5);
assert_eq!(bv.as_raw_slice(), [0xA5; 3]);

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

Sets the uninitialized bits of a bit-vector to a known value.

This method modifies all bits that are observable in .as_raw_slice() but not observable in .as_bitslice() to a known value. Memory beyond the raw-slice view, but still within the allocation, is considered fully dead and will never be seen.

This can be used to zero the unused memory so that when viewed as a raw slice, unused bits have a consistent and predictable value.

§Examples
use bitvec::prelude::*;

let mut bv = 0b1101_1100u8.view_bits::<Lsb0>().to_bitvec();
assert_eq!(bv.as_raw_slice()[0], 0b1101_1100u8);

bv.truncate(4);
assert_eq!(bv.count_ones(), 2);
assert_eq!(bv.as_raw_slice()[0], 0b1101_1100u8);

bv.set_uninitialized(false);
assert_eq!(bv.as_raw_slice()[0], 0b0000_1100u8);

bv.set_uninitialized(true);
assert_eq!(bv.as_raw_slice()[0], 0b1111_1100u8);

pub fn force_align(&mut self)

Ensures that the live region of the bit-vector’s contents begin at the front edge of the buffer.

BitVec has performance optimizations where it moves its view of its buffer contents in order to avoid needless moves of its data within the buffer. This can lead to unexpected contents of the raw memory values, so this method ensures that the semantic contents of the bit-vector match its in-memory storage.

§Examples
use bitvec::prelude::*;

let data = 0b00_1111_00u8;
let bits = data.view_bits::<Msb0>();

let mut bv = bits[2 .. 6].to_bitvec();
assert_eq!(bv, bits![1; 4]);
assert_eq!(bv.as_raw_slice()[0], data);

bv.force_align();
assert_eq!(bv, bits![1; 4]);
// BitVec does not specify the value of dead bits in its buffer.
assert_eq!(bv.as_raw_slice()[0] & 0xF0, 0xF0);

Trait Implementations

§

impl<T, O> AsMut<BitSlice<T, O>> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn as_mut(&mut self) -> &mut BitSlice<T, O>

Converts this type into a mutable reference of the (usually inferred) input type.
§

impl<T, O> AsMut<BitVec<T, O>> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn as_mut(&mut self) -> &mut BitVec<T, O>

Converts this type into a mutable reference of the (usually inferred) input type.
§

impl<T, O> AsRef<BitSlice<T, O>> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn as_ref(&self) -> &BitSlice<T, O>

Converts this type into a shared reference of the (usually inferred) input type.
§

impl<T, O> AsRef<BitVec<T, O>> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn as_ref(&self) -> &BitVec<T, O>

Converts this type into a shared reference of the (usually inferred) input type.
§

impl<T, O> Binary for BitVec<T, O>
where O: BitOrder, T: BitStore,

§

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

Formats the value using the given formatter. Read more
§

impl<T, O, Rhs> BitAnd<Rhs> for BitVec<T, O>
where T: BitStore, O: BitOrder, BitSlice<T, O>: BitAndAssign<Rhs>,

§

type Output = BitVec<T, O>

The resulting type after applying the & operator.
§

fn bitand(self, rhs: Rhs) -> <BitVec<T, O> as BitAnd<Rhs>>::Output

Performs the & operation. Read more
§

impl<T, O, Rhs> BitAndAssign<Rhs> for BitVec<T, O>
where T: BitStore, O: BitOrder, BitSlice<T, O>: BitAndAssign<Rhs>,

§

fn bitand_assign(&mut self, rhs: Rhs)

Performs the &= operation. Read more
§

impl<T, O> BitField for BitVec<T, O>
where T: BitStore, O: BitOrder, BitSlice<T, O>: BitField,

§

fn load_le<I>(&self) -> I
where I: Integral,

Little-Endian Integer Loading Read more
§

fn load_be<I>(&self) -> I
where I: Integral,

Big-Endian Integer Loading Read more
§

fn store_le<I>(&mut self, value: I)
where I: Integral,

Little-Endian Integer Storing Read more
§

fn store_be<I>(&mut self, value: I)
where I: Integral,

Big-Endian Integer Storing Read more
§

fn load<I>(&self) -> I
where I: Integral,

Integer Loading Read more
§

fn store<I>(&mut self, value: I)
where I: Integral,

Integer Storing Read more
§

impl<T, O, Rhs> BitOr<Rhs> for BitVec<T, O>
where T: BitStore, O: BitOrder, BitSlice<T, O>: BitOrAssign<Rhs>,

§

type Output = BitVec<T, O>

The resulting type after applying the | operator.
§

fn bitor(self, rhs: Rhs) -> <BitVec<T, O> as BitOr<Rhs>>::Output

Performs the | operation. Read more
§

impl<T, O, Rhs> BitOrAssign<Rhs> for BitVec<T, O>
where T: BitStore, O: BitOrder, BitSlice<T, O>: BitOrAssign<Rhs>,

§

fn bitor_assign(&mut self, rhs: Rhs)

Performs the |= operation. Read more
§

impl<T, O, Rhs> BitXor<Rhs> for BitVec<T, O>
where T: BitStore, O: BitOrder, BitSlice<T, O>: BitXorAssign<Rhs>,

§

type Output = BitVec<T, O>

The resulting type after applying the ^ operator.
§

fn bitxor(self, rhs: Rhs) -> <BitVec<T, O> as BitXor<Rhs>>::Output

Performs the ^ operation. Read more
§

impl<T, O, Rhs> BitXorAssign<Rhs> for BitVec<T, O>
where T: BitStore, O: BitOrder, BitSlice<T, O>: BitXorAssign<Rhs>,

§

fn bitxor_assign(&mut self, rhs: Rhs)

Performs the ^= operation. Read more
§

impl<T, O> Borrow<BitSlice<T, O>> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn borrow(&self) -> &BitSlice<T, O>

Immutably borrows from an owned value. Read more
§

impl<T, O> BorrowMut<BitSlice<T, O>> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn borrow_mut(&mut self) -> &mut BitSlice<T, O>

Mutably borrows from an owned value. Read more
§

impl<T, O> Clone for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn clone(&self) -> BitVec<T, O>

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
§

impl<T, O> Debug for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

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

Formats the value using the given formatter. Read more
§

impl<O, T> Decode for BitVec<T, O>
where O: BitOrder, T: BitStore + Decode,

§

fn decode<I>(input: &mut I) -> Result<BitVec<T, O>, Error>
where I: Input,

Attempt to deserialise the value from input.
§

fn decode_into<I>( input: &mut I, dst: &mut MaybeUninit<Self>, ) -> Result<DecodeFinished, Error>
where I: Input,

Attempt to deserialize the value from input into a pre-allocated piece of memory. Read more
§

fn skip<I>(input: &mut I) -> Result<(), Error>
where I: Input,

Attempt to skip the encoded value from input. Read more
§

fn encoded_fixed_size() -> Option<usize>

Returns the fixed encoded size of the type. Read more
§

impl<T, O> Default for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn default() -> BitVec<T, O>

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

impl<T, O> Deref for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

type Target = BitSlice<T, O>

The resulting type after dereferencing.
§

fn deref(&self) -> &<BitVec<T, O> as Deref>::Target

Dereferences the value.
§

impl<T, O> DerefMut for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn deref_mut(&mut self) -> &mut <BitVec<T, O> as Deref>::Target

Mutably dereferences the value.
§

impl<'de, T, O> Deserialize<'de> for BitVec<T, O>
where T: BitStore, O: BitOrder, Vec<T>: Deserialize<'de>,

§

fn deserialize<D>( deserializer: D, ) -> Result<BitVec<T, O>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl<T, O> Display for BitVec<T, O>
where O: BitOrder, T: BitStore,

§

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

Formats the value using the given formatter. Read more
§

impl<T, O> Drop for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl<O, T> Encode for BitVec<T, O>
where O: BitOrder, T: BitStore + Encode,

§

fn encode_to<W>(&self, dest: &mut W)
where W: Output + ?Sized,

Convert self to a slice and append it to the destination.
§

fn size_hint(&self) -> usize

If possible give a hint of expected size of the encoding. Read more
§

fn encode(&self) -> Vec<u8>

Convert self to an owned vector.
§

fn using_encoded<R, F>(&self, f: F) -> R
where F: FnOnce(&[u8]) -> R,

Convert self to a slice and then invoke the given closure with it.
§

fn encoded_size(&self) -> usize

Calculates the encoded size. Read more
§

impl<'a, T, O> Extend<&'a T> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

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

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
§

impl<'a, T, O> Extend<&'a bool> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn extend<I>(&mut self, iter: I)
where I: 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
§

impl<'a, M, T1, T2, O1, O2> Extend<BitRef<'a, M, T2, O2>> for BitVec<T1, O1>
where M: Mutability, T1: BitStore, T2: BitStore, O1: BitOrder, O2: BitOrder,

§Bit-Vector Extension by Proxy References

DO NOT use this. You clearly have a bit-slice. Use .extend_from_bitslice() instead!

Iterating over a bit-slice requires loading from memory and constructing a proxy reference for each bit. This is needlessly slow; the specialized method is able to avoid this per-bit cost and possibly even use batched operations.

§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = BitRef<'a, M, T2, O2>>,

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
§

impl<T, O> Extend<T> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

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

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
§

impl<T, O> Extend<bool> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§Bit-Vector Extension

This extends a bit-vector from anything that produces individual bits.

§Original

impl<T> Extend<T> for Vec<T>

§Notes

This .extend() call is the second-slowest possible way to append bits into a bit-vector, faster only than calling iter.for_each(|bit| bv.push(bit)). DO NOT use this if you have any other choice.

If you are extending a bit-vector from the contents of a bit-slice, then you should use .extend_from_bitslice() instead. That method is specialized to perform upfront allocation and, where possible, use a batch copy rather than copying each bit individually from the source into the bit-vector.

§

fn extend<I>(&mut self, iter: I)
where I: 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
§

impl<T, O> From<&BitSlice<T, O>> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn from(slice: &BitSlice<T, O>) -> BitVec<T, O>

Converts to this type from the input type.
§

impl<T, O> From<&mut BitSlice<T, O>> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn from(slice: &mut BitSlice<T, O>) -> BitVec<T, O>

Converts to this type from the input type.
§

impl<A, O> From<BitArray<A, O>> for BitVec<<A as BitView>::Store, O>
where O: BitOrder, A: BitViewSized,

§

fn from(array: BitArray<A, O>) -> BitVec<<A as BitView>::Store, O>

Converts to this type from the input type.
§

impl<T, O> From<BitBox<T, O>> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn from(boxed: BitBox<T, O>) -> BitVec<T, O>

Converts to this type from the input type.
§

impl<'a, T, O> From<Cow<'a, BitSlice<T, O>>> for BitVec<T, O>
where O: BitOrder, T: 'a + BitStore,

§

fn from(cow: Cow<'a, BitSlice<T, O>>) -> BitVec<T, O>

Converts to this type from the input type.
§

impl<'a, T, O> FromIterator<&'a T> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn from_iter<I>(iter: I) -> BitVec<T, O>
where I: IntoIterator<Item = &'a T>,

Creates a value from an iterator. Read more
§

impl<'a, T, O> FromIterator<&'a bool> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn from_iter<I>(iter: I) -> BitVec<T, O>
where I: IntoIterator<Item = &'a bool>,

Creates a value from an iterator. Read more
§

impl<'a, M, T1, T2, O1, O2> FromIterator<BitRef<'a, M, T2, O2>> for BitVec<T1, O1>
where M: Mutability, T1: BitStore, T2: BitStore, O1: BitOrder, O2: BitOrder,

§Bit-Vector Collection from Proxy References

DO NOT use this. You clearly have a bit-slice. Use ::from_bitslice() instead!

Iterating over a bit-slice requires loading from memory and constructing a proxy reference for each bit. This is needlessly slow; the specialized method is able to avoid this per-bit cost and possibly even use batched operations.

§

fn from_iter<I>(iter: I) -> BitVec<T1, O1>
where I: IntoIterator<Item = BitRef<'a, M, T2, O2>>,

Creates a value from an iterator. Read more
§

impl<T, O> FromIterator<T> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn from_iter<I>(iter: I) -> BitVec<T, O>
where I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
§

impl<T, O> FromIterator<bool> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§Bit-Vector Collection

This collects a bit-vector from anything that produces individual bits.

§Original

impl<T> FromIterator<T> for Vec<T>

§Notes

This .collect() call is the second-slowest possible way to collect bits into a bit-vector, faster only than calling iter.for_each(|bit| bv.push(bit)). DO NOT use this if you have any other choice.

If you are collecting a bit-vector from the contents of a bit-slice, then you should use ::from_bitslice() instead. That method is specialized to perform upfront allocation and, where possible, use a batch copy rather than copying each bit individually from the source into the bit-vector.

§

fn from_iter<I>(iter: I) -> BitVec<T, O>
where I: IntoIterator<Item = bool>,

Creates a value from an iterator. Read more
§

impl<T, O> Hash for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<T, O, Idx> Index<Idx> for BitVec<T, O>
where T: BitStore, O: BitOrder, BitSlice<T, O>: Index<Idx>,

§

type Output = <BitSlice<T, O> as Index<Idx>>::Output

The returned type after indexing.
§

fn index(&self, index: Idx) -> &<BitVec<T, O> as Index<Idx>>::Output

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

impl<T, O, Idx> IndexMut<Idx> for BitVec<T, O>
where T: BitStore, O: BitOrder, BitSlice<T, O>: IndexMut<Idx>,

§

fn index_mut(&mut self, index: Idx) -> &mut <BitVec<T, O> as Index<Idx>>::Output

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

impl<T, O> IntoIterator for BitVec<T, O>
where T: BitStore, O: BitOrder,

§Bit-Vector Iteration

Bit-vectors have the advantage that iteration consumes the whole structure, so they can simply freeze the allocation into a bit-box, then use its iteration and destructor.

§Original

impl<T> IntoIterator for Vec<T>

§

type IntoIter = <BitBox<T, O> as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?
§

type Item = <BitBox<T, O> as IntoIterator>::Item

The type of the elements being iterated over.
§

fn into_iter(self) -> <BitVec<T, O> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

impl<T, O> LowerHex for BitVec<T, O>
where O: BitOrder, T: BitStore,

§

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

Formats the value using the given formatter. Read more
§

impl<T, O> Not for BitVec<T, O>
where T: BitStore, O: BitOrder,

This implementation inverts all elements in the live buffer. You cannot rely on the value of bits in the buffer that are outside the domain of [BitVec::as_mut_bitslice].

§

type Output = BitVec<T, O>

The resulting type after applying the ! operator.
§

fn not(self) -> <BitVec<T, O> as Not>::Output

Performs the unary ! operation. Read more
§

impl<T, O> Octal for BitVec<T, O>
where O: BitOrder, T: BitStore,

§

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

Formats the value using the given formatter. Read more
§

impl<T, O> Ord for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

fn cmp(&self, other: &BitVec<T, O>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
§

impl<T, O, Rhs> PartialEq<Rhs> for BitVec<T, O>
where T: BitStore, O: BitOrder, Rhs: PartialEq<BitSlice<T, O>> + ?Sized,

§

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

impl<T, O, Rhs> PartialOrd<Rhs> for BitVec<T, O>
where T: BitStore, O: BitOrder, Rhs: PartialOrd<BitSlice<T, O>> + ?Sized,

§

fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl<T, O> Pointer for BitVec<T, O>
where O: BitOrder, T: BitStore,

§

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

Formats the value using the given formatter. Read more
§

impl<T, O> Read for BitVec<T, O>
where T: BitStore, O: BitOrder, BitSlice<T, O>: BitField,

§Reading From a Bit-Vector

The implementation loads bytes out of the reference bit-vector until either the destination buffer is filled or the source has no more bytes to provide. When .read() returns, the provided bit-vector will have its contents shifted down so that it begins at the first bit after the last byte copied out into buf.

Note that the return value of .read() is always the number of bytes of buf filled!

§API Differences

The standard library does not impl Read for Vec<u8>. It is provided here as a courtesy.

§

fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · Source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
Source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Reads all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads the exact number of bytes required to fill buf. Read more
Source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
Source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
§

impl<T, O> Serialize for BitVec<T, O>
where T: BitStore, O: BitOrder, BitSlice<T, O>: Serialize,

§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl<T, O> TryFrom<Vec<T>> for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

type Error = Vec<T>

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

fn try_from( vec: Vec<T>, ) -> Result<BitVec<T, O>, <BitVec<T, O> as TryFrom<Vec<T>>>::Error>

Performs the conversion.
§

impl<T, O> TypeInfo for BitVec<T, O>
where T: BitStore + TypeInfo + 'static, O: BitOrder + TypeInfo + 'static,

§

type Identity = BitVec<T, O>

The type identifying for which type info is provided. Read more
§

fn type_info() -> Type

Returns the static type identifier for Self.
§

impl<T, O> UpperHex for BitVec<T, O>
where O: BitOrder, T: BitStore,

§

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

Formats the value using the given formatter. Read more
§

impl<T, O> Write for BitVec<T, O>
where O: BitOrder, T: BitStore, BitSlice<T, O>: BitField,

§Writing Into a Bit-Vector

The implementation appends bytes to the referenced bit-vector until the source buffer is exhausted.

Note that the return value of .write() is always the number of bytes of buf consumed!

The implementation uses BitField::store_be to fill bytes. Note that unlike the standard library, it is implemented on bit-vectors of any underlying element type. However, using a BitVec<_, u8> is still likely to be fastest.

§Original

impl Write for Vec<u8>

§

fn write(&mut self, buf: &[u8]) -> Result<usize, Error>

Writes a buffer into this writer, returning how many bytes were written. Read more
§

fn flush(&mut self) -> Result<(), Error>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more
§

impl<O, T> DecodeWithMemTracking for BitVec<T, O>
where O: BitOrder, T: BitStore + Decode,

§

impl<O, T> EncodeLike for BitVec<T, O>
where O: BitOrder, T: BitStore + Encode,

§

impl<T, O> Eq for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

impl<T, O> Send for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

impl<T, O> Sync for BitVec<T, O>
where T: BitStore, O: BitOrder,

§

impl<T, O> Unpin for BitVec<T, O>
where T: BitStore, O: BitOrder,