[][src]Struct bitvec::vec::BitVec

#[repr(C)]pub struct BitVec<O = Lsb0, T = usize> where
    O: BitOrder,
    T: BitStore
{ /* fields omitted */ }

A vector of individual bits, allocated on the heap.

This is a managed, heap-allocated, buffer that contains a BitSlice region. It is analagous to Vec<bool>, and is written to be as close as possible to drop-in replacabale for it. This type contains little interesting behavior in its own right, dereferencing instead to BitSlice for manipulation of the buffer contents, and serves primarily as an interface to the allocator. If you require statically-allocated, fixed-size, owned buffers, you should use the BitArray type.

Because BitVec directly owns its memory, and can guarantee that no other object in a program has access to its buffers, BitVec is able to override some behavior from BitSlice in more efficient manners.

Documentation

All APIs that mirror something in the standard library will have an Original section linking to the corresponding item. All APIs that have a different signature or behavior than the original will have an API Differences section explaining what has changed, and how to adapt your existing code to the change.

These sections look like this:

Original

Vec<T>

API Differences

The buffer type Vec<bool> has no type parameters. BitVec<O, T> has the same two type parameters as BitSlice<O, T>. Otherwise, BitVec is able to implement the full API surface of Vec<bool>.

Behavior

Because BitVec is a fully-owned buffer, it is able to operate on its memory without concern for any other views that may alias. This enables it to specialize some BitSlice behavior to be faster or more efficient.

Type Parameters

This takes the same two type parameters, O: BitOrder and T: BitStore, as BitSlice.

Safety

Like BitSlice, BitVec is exactly equal in size to Vec, and is also absolutely representation-incompatible with it. You must never attempt to type-cast between Vec<T> and BitVec in any way, nor attempt to modify the memory value of a BitVec handle. Doing so will cause allocator and memory errors in your program, likely inducing a panic.

Everything in the BitVec public API, even the unsafe parts, are guaranteed to have no more unsafety than their equivalent items in the standard library. All unsafe APIs will have documentation explicitly detailing what the API requires you to uphold in order for it to function safely and correctly. All safe APIs will do so themselves.

Performance

The choice of T: BitStore type parameter can impact your vector’s performance, as the allocator operates in units of T rather than in bits. This means that larger register types will increase the amount of memory reserved in each call to the allocator, meaning fewer calls to .push() will actually cause a reällocation. In addition, iteration over the vector is governed by the BitSlice characteristics on the type parameter. You are generally better off using larger types when your vector is a data collection rather than a specific I/O protocol buffer.

Macro Construction

Heap allocation can only occur at runtime, but the bitvec! macro will construct an appropriate BitSlice buffer at compile-time, and at run-time, only copy the buffer into a heap allocation.

Implementations

impl<O, T> BitVec<O, T> where
    O: BitOrder,
    T: BitStore
[src]

pub fn new() -> Self[src]

Constructs a new, empty BitVec<O, T>.

The vector will not allocate until bits are pushed into it.

Original

Vec::new

Examples

use bitvec::prelude::*;

let mut bv = BitVec::<LocalBits, usize>::new();

pub fn with_capacity(capacity: usize) -> Self[src]

Constructs a new, empty BitVec<O, T> with the specified capacity.

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

It is important to note that although the returned vector has the capacity specified, the vector will have a zero length. For an explanation of the difference between length and capacity, see Capacity and reällocation.

Original

Vec::with_capacity

Panics

Panics if the requested capacity exceeds the vector’s limits.

Examples

use bitvec::prelude::*;

let mut bv = BitVec::<LocalBits, usize>::with_capacity(10);

// The vector contains no items, even though it has capacity for more
assert_eq!(bv.len(), 0);

// These are all done without reallocating...
for i in 0..10 {
  bv.push(true);
}

// ...but this may make the vector reallocate
bv.push(false);

pub unsafe fn from_raw_parts(
    pointer: *mut BitSlice<O, T>,
    capacity: usize
) -> Self
[src]

Creates a BitVec<O, T> directly from the raw components of another bit-vector.

Original

Vec::from_raw_parts

API Differences

Ordinary vectors decompose into their buffer pointer and element length separately; bit vectors must keep these two components bundled into the *BitSlice region pointer. As such, this only accepts two components; the slice pointer and the buffer capacity.

Vec could define its raw parts as *[T] and usize also, but Rust does not make working with raw slice pointers easy.

Panics

This function panics if pointer is the null pointer.

Safety

This is highly unsafe, due to the number of invariants that aren’t checked:

  • pointer needs to have been previously allocated via BitVec<O, T> (at least, it’s highly likely to be incorrect if it wasn’t).
  • T needs to have the same size and alignment as what pointer was allocated with. (T having a less strict alignment is not sufficient; the alignment really needs to be equal to satisfy the [dealloc] requirement that memory must be allocated and deällocated with the same layout.)
  • capacity needs to be the capacity that the pointer was allocated with.

In addition to the invariants inherited from Vec::from_raw_parts, the fact that this function takes a bit-slice pointer adds another one:

  • pointer MUST NOT have had its value modified in any way in the time when it was outside of a bitvec container type.

Violating these will cause problems like corrupting the allocator’s internal data structures. For example it is not safe to build a BitVec<_, u8> from a pointer to a C char array with length size_t. It’s also not safe to build one from a BitVec<_, u16> and its length, becauset the allocator cares about the alignment, and these two types have different alignments. The buffer was allocated with alignment 2 (for u16), but after turning it into a BitVec<_, u8>, it’ll be deällocated with alignment 1.

The ownership of pointer is effectively transferred to the BitVec<O, T> which may then deällocate, reällocate, or change the contents of memory pointed to by the pointer at will. Ensure that nothing else uses the pointer after calling this function.

Examples

use bitvec::prelude::*;
use bitvec as bv;
use core::mem;

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

// Prevent running `bv`’s destructor so we are in complete control
// of the allocation.
let mut bv = mem::ManuallyDrop::new(bv);

// Pull out the various important pieces of information about `bv`
let p = bv.as_mut_ptr();
let e = bv.elements();
let cap = bv.capacity();

unsafe {
  let bits = bv::slice::from_raw_parts_mut::<LocalBits, _>(p, e);
  let len = bits.len();

  // Overwrite memory with a new pattern
  bits.iter_mut().for_each(|mut b| *b = true);

  // Put everything back together into a BitVec
  let rebuilt = BitVec::from_raw_parts(bits as *mut _, cap);
  assert_eq!(rebuilt.len(), len);
}

pub fn capacity(&self) -> usize[src]

Returns the number of bits the vector can hold without reällocating.

Original

Vec::capacity

Examples

use bitvec::prelude::*;

let bv: BitVec<LocalBits, usize> = BitVec::with_capacity(100);
assert!(bv.capacity() >= 100);

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

Reserves capacity for at least additional more bits to be inserted in the given BitVec<O, T>. The collection may reserve more space to avoid frequent reällocations. After calling reserve, capacity will be greater than or equal to self.len() + additional. Does nothing if capacity is already sufficient.

Original

Vec::reserve

Panics

Panics if the new capacity exceeds the vector’s limits.

Examples

use bitvec::prelude::*;

let mut bv = bitvec![1];
bv.reserve(100);
assert!(bv.capacity() >= 101);

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

Reserves the minimum capacity for exactly additional more bits to be inserted in the given BitVec<O, T>. After calling reserve_exact, capacity will be greater than or equal to self.len() + additional. Does nothing if the capacity is already sufficient.

Note that the allocator may give the collection more space than it requests. Therefore, capacity can not be relied upon to be precisely minimal. Prefer reserve if future insertions are expected.

Original

Vec::reserve_exact

Panics

Panics if the new capacity exceeds the vector’s limits.

Examples

use bitvec::prelude::*;

let mut bv = bitvec![1];
bv.reserve_exact(100);
assert!(bv.capacity() >= 101);

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity of the vector as much as possible.

It will drop down as close as possible to the length but the allocator may still inform the vector that there is space for a few more bits.

Original

Vec::shrink_to_fit

Examples

use bitvec::prelude::*;

let mut bv = BitVec::<LocalBits, usize>::with_capacity(100);
bv.extend([false, true, false].iter().copied());
assert!(bv.capacity() >= 100);
bv.shrink_to_fit();
assert!(bv.capacity() >= 3);

pub fn into_boxed_slice(self) -> Box<[T]>[src]

Converts the vector into [Box<[T]>].

Note that this will drop any excess capacity.

Original

Vec::into_boxed_slice

Analogue

See [into_boxed_bitslice] for a BitVec -> BitBox transform.

Examples

use bitvec::prelude::*;

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

let slice = bv.into_boxed_slice();
assert_eq!(slice.len(), 1);

Any excess capacity is removed:

use bitvec::prelude::*;

let mut bv: BitVec = BitVec::with_capacity(100);
bv.extend([false, true, false].iter().copied());

assert!(bv.capacity() >= 100);
let slice = bv.into_boxed_slice();
assert_eq!(slice.into_vec().capacity(), 1);

[Box<[T]>]: https://doc.rust-lang.org/alloc/boxed/struct.Box.html [into_boxed_bitslice]: #method.into_boxed_bitslice

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

Shortens the vector, keeping the first len bits and dropping the rest.

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

The drain method can emulate truncate, but causes the excess bits to be returned instead of dropped.

Note that this method has no effect on the allocated capacity of the vector.

Original

Vec::truncate

Examples

Truncating a five bit vector to two bits:

use bitvec::prelude::*;

let mut bv = bitvec![1; 5];
bv.truncate(2);
assert_eq!(bv.len(), 2);

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

use bitvec::prelude::*;

let mut bv = bitvec![1; 3];
bv.truncate(8);
assert_eq!(bv.len(), 3);

Truncating when len == 0 is equivalent to calling the [clean] method.

use bitvec::prelude::*;

let mut bv = bitvec![0; 3];
bv.truncate(0);
assert!(bv.is_empty());

pub fn as_slice(&self) -> &[T][src]

Extracts an element slice containing the entire vector.

Original

Vec::as_slice

Analogue

See as_bitslice for a &BitVec -> &BitSlice transform.

Examples

use bitvec::prelude::*;
use std::io::{self, Write};
let buffer = bitvec![Msb0, u8; 0, 1, 0, 1, 1, 0, 0, 0];
io::sink().write(buffer.as_slice()).unwrap();

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

Extracts a mutable slice of the entire vector.

Original

Vec::as_mut_slice

Analogue

See as_mut_bitslice for a &mut BitVec -> &mut BitSlice transform.

Examples

use bitvec::prelude::*;
use std::io::{self, Read};
let mut buffer = bitvec![Msb0, u8; 0; 24];
io::repeat(0b101).read_exact(buffer.as_mut_slice()).unwrap();

pub fn as_ptr(&self) -> *const T[src]

Returns a raw pointer to the vector’s buffer.

The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage. Modifying the vector may cause its buffer to be reällocated, which would also make any pointers to it invalid.

The caller must also ensure that the memory the pointer (non-transitively) points to is never written to (except inside an UnsafeCell) using this pointer or any pointer derived from it. If you need to mutate the contents of the slice, use [as_mut_ptr].

Original

Vec::as_ptr

Analogue

See [as_bitptr] for a &BitVec -> *const BitSlice transform.

Examples

use bitvec::prelude::*;

let bv = bitvec![Lsb0; 0, 1, 0, 1];
let bv_ptr = bv.as_ptr();

unsafe {
  assert_eq!(*bv_ptr, 0b1010);
}

pub fn as_mut_ptr(&mut self) -> *mut T[src]

Returns an unsafe mutable pointer to the vector’s buffer.

The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage. Modifying the vector may cause its buffer to be reällocated, which would also make any pointers to it invalid.

Original

Vec::as_mut_ptr

Analogue

See as_mut_bitptr for a &mut BitVec -> *mut BitSlice transform.

Eaxmples

use bitvec::prelude::*;

let size = 4;
let mut bv: BitVec<Msb0, usize> = BitVec::with_capacity(size);
let bv_ptr = bv.as_mut_ptr();

unsafe {
  *bv_ptr = !0;
  bv.set_len(size);
}
assert_eq!(bv.len(), 4);
assert!(bv.all());

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

Forces the length of the vector to new_len.

This is a low-level operation that maintains none of the normal invariants of the type. Normally changing the length of a vector is done using one of the safe operations instead, such as truncate, resize, extend, or clear.

Original

Vec::set_len

Safety

  • new_len must be less than or equal to capacity().

Examples

This method can be useful for situations in which the vector is serving as a buffer for other code, particularly over FFI:

use bitvec::prelude::*;

// `bitvec` could pair with `rustler` for a better bitstream
type ErlBitstring = BitVec<Msb0, u8>;
let mut bits_read = 0;
// An imaginary Erlang function wants a large bit buffer.
let mut buf = ErlBitstring::with_capacity(32_768);
// SAFETY: When `erl_read_bits` returns `ERL_OK`, it holds that:
// 1. `bits_read` bits were initialized.
// 2. `bits_read` <= the capacity (32_768)
// which makes `set_len` safe to call.
unsafe {
  // Make the FFI call...
  let status = erl_read_bits(&mut buf, 10, &mut bits_read);
  if status == ERL_OK {
    // ...and update the length to what was read in.
    buf.set_len(bits_read);
  }
}

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

Removes a bit from the vector and returns it.

The removed bit is replaced by the last bit of the vector.

This does not preserve ordering, but is O(1).

Original

Vec::swap_remove

Panics

Panics if index is out of bounds.

Examples

use bitvec::prelude::*;

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

assert!(!bv.swap_remove(0));
assert_eq!(bv, bits![0, 1, 1]);

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

Inserts a bit at position index within the vector, shifting all bits after it to the right.

Original

Vec::insert

Panics

Panics if index > len.

Examples

use bitvec::prelude::*;

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

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

Removes and returns the bit at position index within the vector, shifting all bits after it to the left.

Original

Vec::remove

Panics

Panics if index is out of bounds.

Examples

use bitvec::prelude::*;

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

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

Retains only the bits specified by the predicate.

In other words, remove all bits b such that func(idx(b), &b) returns false. This method operates in place, visiting each bit exactly once in the original order, and preserves the order of the retained bits.

Original

Vec::retain

API Differences

In order to allow more than one bit of information for the split decision, the predicate receives the index of each bit, as well as its value.

Examples

use bitvec::prelude::*;

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

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

Appends a bit to the back of a collection.

Original

Vec::push

Panics

Panics if the number of bits in the vector exceeds the maximum vector capacity.

Examples

use bitvec::prelude::*;

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

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

Removes the last bit from a vector and returns it, or None if it is empty.

Original

Vec::pop

Examples

use bitvec::prelude::*;

let mut bv = bitvec![0, 0, 1];
assert_eq!(bv.pop(), Some(true));
assert!(bv.not_any());

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

Moves all the bits of other into self, leaving other empty.

Original

Vec::append

Panics

Panics if the number of bits overflows the maximum vector capacity.

Examples

use bitvec::prelude::*;

let mut bv1 = bitvec![0; 10];
let mut bv2 = bitvec![1; 10];

bv1.append(&mut bv2);

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

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

Notable traits for Drain<'_, O, T>

impl<O, T, '_> Iterator for Drain<'_, O, T> where
    O: BitOrder,
    T: BitStore
type Item = bool;
where
    R: RangeBounds<usize>, 
[src]

Creates a draining iterator that removes the specified range in the vector and yields the removed items.

Note 1: The bit range is removed even if the iterator is only partially consumed or not consumed at all.

Note 2: It is unspecified how many bits are removed from the vector if the Drain value is leaked.

Original

Vec::drain

Panics

Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector.

Examples

use bitvec::prelude::*;

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

// A full range clears the vector
bv.drain(..);
assert_eq!(bv, bits![]);

pub fn clear(&mut self)[src]

Clears the vector, removing all values.

Note that this method has no effect on the allocated capacity of the vector.

Original

Vec::clear

Examples

use bitvec::prelude::*;

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

bv.clear();

assert!(bv.is_empty());

pub fn split_off(&mut self, at: usize) -> Self[src]

Splits the collection into two at the given index.

Returns a newly allocated vector containing the elements in range [at, len). After the call, the original vector will be left containing the bits [0, at) with its previous capacity unchanged.

Original

Vec::split_off

Panics

Panics if at > len.

Examples

use bitvec::prelude::*;

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

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

Resizes the BitVec in-place so that len is equal to new_len.

If new_len is greater than len, the BitVec is extended by the difference, with each additional slot filled with the result of calling the closure func. The return values from func will end up in the BitVec in the order they have been generated.

If new_len is less than len, the Vec is simply truncated.

This method uses a closure to create new values on every push. If you’d rather Clone a given bit, use resize. If you want to use the Default trait to generate values, you can pass Default::default as the second argument.

Original

Vec::resize_with

Examples

use bitvec::prelude::*;

let mut bv = bitvec![1; 3];
bv.resize_with(5, Default::default);
assert_eq!(bv, bits![1, 1, 1, 0, 0]);

let mut bv = bitvec![];
let mut p = 0;
bv.resize_with(4, || { p += 1; p % 2 == 0 });
assert_eq!(bv, bits![0, 1, 0, 1]);

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

Resizes the BitVec in-place so that len is equal to new_len.

If new_len is greater than len, the BitVec is extended by the difference, with each additional slot filled with value. If new_len is less than len, the BitVec is simply truncated.

This method requires a single bool value. If you need more flexibility, use resize_with.

Original

Vec::resize

Examples

use bitvec::prelude::*;

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

let mut bv = bitvec![1; 4];
bv.resize(2, false);
assert_eq!(bv, bits![1; 2]);

pub fn extend_from_slice(&mut self, other: &[bool])[src]

Clones and appends all bools in a slice to the BitVec.

Iterates over the slice other, clones each bool, and then appends it to the BitVec. The other slice is traversed in-order.

Prefer the Extend implementation; this method is retained only for API compatibility, and offers no performance benefit.

Original

Vec::extend_from_slice

Analogue

See [extend_from_bitslice] for the method to append a bit-slice of the same type parameters to a bit-vector.

Examples

use bitvec::prelude::*;

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

[extend]: #impl-Extend<%26'a bool> [extend_from_bitslice]: #method.extend_from_bitslice

pub fn splice<R, I>(
    &mut self,
    range: R,
    replace_with: I
) -> Splice<'_, O, T, I::IntoIter>

Notable traits for Splice<'_, O, T, I>

impl<O, T, I, '_> Iterator for Splice<'_, O, T, I> where
    O: BitOrder,
    T: BitStore,
    I: Iterator<Item = bool>, 
type Item = bool;
where
    R: RangeBounds<usize>,
    I: IntoIterator<Item = bool>, 
[src]

Creates a splicing iterator that replaces the specified range in the vector with the given replace_with iterator and yields the removed items. replace_with does not need to be the same length as range.

The element range is removed even if the iterator is not consumed until the end.

It is unspecified how many bits are removed from the vector if the Splice value is leaked.

The input iterator replace_with is only consumed when the Splice value is dropped.

This is optimal if:

  • the tail (bits in the vector after range) is empty
  • or replace_with yields fewer bits than range’s length
  • or the lower bound of its size_hint() is exact

Otherwise, a temporary vector is allocated and the tail is moved twice.

Original

Vec::splice

Examples

use bitvec::prelude::*;

let mut bv = bitvec![0, 1, 0];
let new = bits![1, 0];
let old: BitVec = bv.splice(.. 2, new.iter().copied()).collect();
assert_eq!(bv, bits![1, 0, 0]);
assert_eq!(old, bits![0, 1]);

impl<O, T> BitVec<O, T> where
    O: BitOrder,
    T: BitStore
[src]

Methods specific to BitVec<_, T>, and not present on Vec<T>.

pub fn repeat(bit: bool, len: usize) -> Self[src]

Constructs a BitVec from a value repeated many times.

This function is equivalent to the bitvec![O, T; bit; len] macro call, and is in fact the implementation of that macro syntax.

Parameters

  • bit: The bit value to which all len allocated bits will be set.
  • len: The number of live bits in the constructed BitVec.

Returns

A BitVec with len live bits, all set to bit.

pub fn from_bitslice(slice: &BitSlice<O, T>) -> Self[src]

Clones a &BitSlice into a BitVec.

Original

<Vec<T: Clone> as Clone>::clone

Effects

This performs a direct element-wise copy from the source slice to the newly-allocated buffer, then sets the vector to have the same starting bit as the slice did. This allows for faster behavior. If you require that the vector start at the leading edge of the first element, use force_align to guarantee this.

Examples

use bitvec::prelude::*;

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

pub fn from_vec(vec: Vec<T>) -> Self[src]

Converts a Vec<T> into a BitVec<O, T> without copying its buffer.

Parameters

  • vec: A vector to view as bits.

Returns

A BitVec over the vec buffer.

Panics

This panics if vec is too long to convert into a BitVec. See BitSlice::MAX_ELTS.

Examples

use bitvec::prelude::*;

let vec = vec![0u8; 4];
let bv = BitVec::<LocalBits, _>::from_vec(vec);
assert_eq!(bv, bits![0; 32]);

pub fn try_from_vec(vec: Vec<T>) -> Result<Self, Vec<T>>[src]

Converts a Vec<T> into a BitVec<O, T> without copying its buffer.

This method takes ownership of a memory buffer and enables it to be used as a bit-vector. Because Vec can be longer than BitVecs, this is a fallible method, and the original vector will be returned if it cannot be converted.

Parameters

  • vec: Some vector of memory, to be viewed as bits.

Returns

If vec is short enough to be viewed as a BitVec, then this returns a BitVec over the vec buffer. If vec is too long, then this returns vec unmodified.

Examples

use bitvec::prelude::*;

let vec = vec![0u8; 4];
let bv = BitVec::<LocalBits, _>::try_from_vec(vec).unwrap();
assert_eq!(bv, bits![0; 32]);

An example showing this function failing would require an allocation exceeding !0usize >> 3 bytes in size, which is infeasible to produce.

pub fn extend_from_bitslice(&mut self, other: &BitSlice<O, T>)[src]

Copies all bits in a BitSlice into the BitVec.

This is provided for API completeness; it has no performance benefits compared to use of the Extend implementation.

Parameters

  • &mut self
  • other: A BitSlice reference of the same type parameters as self.

Behavior

self is extended by the length of other, and then the contents of other are copied into the newly-allocated end of self.

use bitvec::prelude::*;

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

assert_eq!(bv, bits![0, 1, 1, 1, 0, 1]);

Extend: #impl-Extend<%26'a bool> [.as_bitslice()]: #method.as_bitslice()

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

Converts the vector into BitBox<O, T>.

Note that this will drop any excess capacity.

Original

Vec::into_boxed_slice

Examples

use bitvec::prelude::*;

let mut bv = bitvec![1; 50];
let bb: BitBox = bv.into_boxed_bitslice();
assert_eq!(bb, bits![1; 50]);

pub fn into_vec(self) -> Vec<T>[src]

Converts the vector back into an ordinary vector of memory elements.

This does not affect the vector’s buffer, only the handle used to control it.

Parameters

  • self

Returns

An ordinary vector containing all of the bit-vector’s memory buffer.

Examples

use bitvec::prelude::*;

let bv = bitvec![0; 5];
let vec = bv.into_vec();
assert_eq!(vec, [0]);

pub fn elements(&self) -> usize[src]

Gets the number of elements T that contain live bits of the vector.

Examples

use bitvec::prelude::*;

let bv = bitvec![LocalBits, u16; 1; 50];
assert_eq!(bv.elements(), 4);

pub fn force_align(&mut self)[src]

Ensures that the live region of the vector’s contents begins at the leading edge of the buffer.

Examples

use bitvec::prelude::*;

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

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

bv.force_align();
assert_eq!(bv, bits[2 .. 6]);
//  It is not specified what happens to bits that are no longer used.
assert_eq!(bv.as_slice()[0] & 0xF0, 0xF0);

pub fn set_elements(&mut self, element: T::Mem)[src]

Writes a value into every element that the vector considers live.

This unconditionally writes element into each live location in the backing buffer, without altering the BitVec’s length or capacity.

It is unspecified what effects this has on the allocated but dead elements in the buffer.

Parameters

  • &mut self
  • element: The value which will be written to each live location in the vector’s buffer.

Examples

use bitvec::prelude::*;

let mut bv = bitvec![LocalBits, u8; 0; 10];
assert_eq!(bv.as_slice(), [0, 0]);
bv.set_elements(0xA5);
assert_eq!(bv.as_slice(), [0xA5, 0xA5]);

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

Notable traits for &'a BitSlice<O, T>

impl<'a, O, T> Read for &'a BitSlice<O, T> where
    O: BitOrder,
    T: BitStore,
    BitSlice<O, T>: BitField
impl<'a, O, T> Write for &'a mut BitSlice<O, T> where
    O: BitOrder,
    T: BitStore,
    BitSlice<O, T::Alias>: BitField
[src]

Views the buffer’s contents as a BitSlice.

This is equivalent to &bv[..].

Original

Vec::as_slice

Examples

use bitvec::prelude::*;

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

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

Notable traits for &'a BitSlice<O, T>

impl<'a, O, T> Read for &'a BitSlice<O, T> where
    O: BitOrder,
    T: BitStore,
    BitSlice<O, T>: BitField
impl<'a, O, T> Write for &'a mut BitSlice<O, T> where
    O: BitOrder,
    T: BitStore,
    BitSlice<O, T::Alias>: BitField
[src]

Extracts a mutable bit-slice of the entire vector.

Equivalent to &mut bv[..].

Original

Vec::as_mut_slice

Examples

use bitvec::prelude::*;

let mut bv = bitvec![0, 1, 0, 1];
let bits = bv.as_mut_bitslice();
bits.set(0, true);

pub fn as_bitptr(&self) -> *const BitSlice<O, T>[src]

Returns a raw pointer to the vector’s region.

The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage. Modifying the vector may cause its buffer to be reallocated, which would also make any pointers to it invalid.

The caller must also ensure that the memory the pointer (non-transitively) points to is never written to (except inside an UnsafeCell) using this pointer or any pointer derived from it. If you need to mutate the contents of the region, use as_mut_bitptr.

This pointer is an opaque crate-internal type. Its in-memory representation is unsafe to modify in any way. The only safe action to take with this pointer is to pass it, unchanged, back into a bitvec API.

Examples

use bitvec::prelude::*;

let bv = bitvec![0; 20];
let ptr = bv.as_bitptr();

let bits = unsafe { &*ptr };
assert_eq!(bv, bits);

pub fn as_mut_bitptr(&mut self) -> *mut BitSlice<O, T>[src]

Returns an unsafe mutable pointer to the vector’s region.

The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage. Modifying the vector may cause its buffer to be reallocated, which would also make any pointers to it invalid.

This pointer is an opaque crate-internal type. Its in-memory representation is unsafe to modify in any way. The only safe action to take with this pointer is to pass it, unchanged, back into a bitvec API.

Examples

use bitvec::prelude::*;

let mut bv = bitvec![0; 20];
let ptr = bv.as_mut_bitptr();

let bits = unsafe { &mut *ptr };
assert_eq!(bv, bits);

Methods from Deref<Target = BitSlice<O, T>>

pub fn len(&self) -> usize[src]

Returns the number of bits in the slice.

Original

slice::len

Examples

use bitvec::prelude::*;

let data = 0u32;
let bits = data.view_bits::<LocalBits>();
assert_eq!(bits.len(), 32);

pub fn is_empty(&self) -> bool[src]

Returns true if the slice has a length of 0.

Original

slice::is_empty

Examples

use bitvec::prelude::*;

assert!(BitSlice::<LocalBits, u8>::empty().is_empty());
assert!(!(0u32.view_bits::<LocalBits>()).is_empty());

pub fn first(&self) -> Option<&bool>[src]

Returns the first bit of the slice, or None if it is empty.

Original

slice::first

Examples

use bitvec::prelude::*;

let data = 1u8;
let bits = data.view_bits::<Lsb0>();
assert_eq!(Some(&true), bits.first());

let empty = BitSlice::<LocalBits, usize>::empty();
assert_eq!(None, empty.first());

pub fn first_mut(&mut self) -> Option<BitMut<'_, O, T>>[src]

Returns a mutable pointer to the first bit of the slice, or None if it is empty.

Original

slice::first_mut

API Differences

This crate cannot manifest &mut bool references, and must use the BitMut proxy type where &mut bool exists in the standard library API. The proxy value must be bound as mut in order to write through it.

Examples

use bitvec::prelude::*;

let mut data = 0u8;
let bits = data.view_bits_mut::<Lsb0>();

if let Some(mut first) = bits.first_mut() {
  *first = true;
}
assert_eq!(data, 1);

pub fn split_first(&self) -> Option<(&bool, &Self)>[src]

Returns the first and all the rest of the bits of the slice, or None if it is empty.

Original

slice::split_first

Examples

use bitvec::prelude::*;

let data = 1u8;
let bits = data.view_bits::<Lsb0>();
if let Some((first, rest)) = bits.split_first() {
  assert!(*first);
}

pub fn split_first_mut(
    &mut self
) -> Option<(BitMut<'_, O, T::Alias>, &mut BitSlice<O, T::Alias>)>
[src]

Returns the first and all the rest of the bits of the slice, or None if it is empty.

Original

slice::split_first_mut

API Differences

This crate cannot manifest &mut bool references, and must use the BitMut proxy type where &mut bool exists in the standard library API. The proxy value must be bound as mut in order to write through it.

Because the references are permitted to use the same memory address, they are marked as aliasing in order to satisfy Rust’s requirements about freedom from data races.

Examples

use bitvec::prelude::*;

let mut data = 0usize;
let bits = data.view_bits_mut::<Lsb0>();

if let Some((mut first, rest)) = bits.split_first_mut() {
  *first = true;
  *rest.get_mut(1).unwrap() = true;
}
assert_eq!(data, 5);

assert!(BitSlice::<LocalBits, usize>::empty_mut().split_first_mut().is_none());

pub fn split_last(&self) -> Option<(&bool, &Self)>[src]

Returns the last and all the rest of the bits of the slice, or None if it is empty.

Original

slice::split_last

Examples

use bitvec::prelude::*;

let data = 1u8;
let bits = data.view_bits::<Msb0>();

if let Some((last, rest)) = bits.split_last() {
  assert!(*last);
}

pub fn split_last_mut(
    &mut self
) -> Option<(BitMut<'_, O, T::Alias>, &mut BitSlice<O, T::Alias>)>
[src]

Returns the last and all the rest of the bits of the slice, or None if it is empty.

Original

slice::split_last_mut

API Differences

This crate cannot manifest &mut bool references, and must use the BitMut proxy type where &mut bool exists in the standard library API. The proxy value must be bound as mut in order to write through it.

Because the references are permitted to use the same memory address, they are marked as aliasing in order to satisfy Rust’s requirements about freedom from data races.

Examples

use bitvec::prelude::*;

let mut data = 0u8;
let bits = data.view_bits_mut::<Msb0>();

if let Some((mut last, rest)) = bits.split_last_mut() {
  *last = true;
  *rest.get_mut(5).unwrap() = true;
}
assert_eq!(data, 5);

assert!(BitSlice::<LocalBits, usize>::empty_mut().split_last_mut().is_none());

pub fn last(&self) -> Option<&bool>[src]

Returns the last bit of the slice, or None if it is empty.

Original

slice::last

Examples

use bitvec::prelude::*;

let data = 1u8;
let bits = data.view_bits::<Msb0>();
assert_eq!(Some(&true), bits.last());

let empty = BitSlice::<LocalBits, usize>::empty();
assert_eq!(None, empty.last());

pub fn last_mut(&mut self) -> Option<BitMut<'_, O, T>>[src]

Returns a mutable pointer to the last bit of the slice, or None if it is empty.

Original

slice::last_mut

API Differences

This crate cannot manifest &mut bool references, and must use the BitMut proxy type where &mut bool exists in the standard library API. The proxy value must be bound as mut in order to write through it.

Examples

use bitvec::prelude::*;

let mut data = 0u8;
let bits = data.view_bits_mut::<Msb0>();

if let Some(mut last) = bits.last_mut() {
  *last = true;
}
assert_eq!(data, 1);

pub fn get<'a, I>(&'a self, index: I) -> Option<I::Immut> where
    I: BitSliceIndex<'a, O, T>, 
[src]

Returns a reference to an element or subslice depending on the type of index.

  • If given a position, returns a reference to the element at that position or None if out of bounds.
  • If given a range, returns the subslice corresponding to that range, or None if out of bounds.

Original

slice::get

Examples

use bitvec::prelude::*;

let data = 2u8;
let bits = data.view_bits::<Lsb0>();

assert_eq!(Some(&true), bits.get(1));
assert_eq!(Some(&bits[1 .. 3]), bits.get(1 .. 3));
assert_eq!(None, bits.get(9));
assert_eq!(None, bits.get(8 .. 10));

pub fn get_mut<'a, I>(&'a mut self, index: I) -> Option<I::Mut> where
    I: BitSliceIndex<'a, O, T>, 
[src]

Returns a mutable reference to an element or subslice depending on the type of index (see get) or None if the index is out of bounds.

Original

slice::get_mut

API Differences

When I is usize, this returns BitMut instead of &mut bool.

Examples

use bitvec::prelude::*;

let mut data = 0u16;
let bits = data.view_bits_mut::<Lsb0>();

assert!(!bits.get(1).unwrap());
*bits.get_mut(1).unwrap() = true;
assert!(bits.get(1).unwrap());

pub unsafe fn get_unchecked<'a, I>(&'a self, index: I) -> I::Immut where
    I: BitSliceIndex<'a, O, T>, 
[src]

Returns a reference to an element or subslice, without doing bounds checking.

This is generally not recommended; use with caution!

Unlike the original slice function, calling this with an out-of-bounds index is not technically compile-time undefined behavior, as the references produced do not actually describe local memory. However, the use of an out-of-bounds index will eventually cause an out-of-bounds memory read, which is a runtime safety violation. For a safe alternative see get.

Original

slice::get_unchecked

Examples

use bitvec::prelude::*;

let data = 2u16;
let bits = data.view_bits::<Lsb0>();

unsafe{
  assert_eq!(bits.get_unchecked(1), &true);
}

pub unsafe fn get_unchecked_mut<'a, I>(&'a mut self, index: I) -> I::Mut where
    I: BitSliceIndex<'a, O, T>, 
[src]

Returns a mutable reference to the output at this location, without doing bounds checking.

This is generally not recommended; use with caution!

Unlike the original slice function, calling this with an out-of-bounds index is not technically compile-time undefined behavior, as the references produced do not actually describe local memory. However, the use of an out-of-bounds index will eventually cause an out-of-bounds memory write, which is a runtime safety violation. For a safe alternative see get_mut.

Original

slice::get_unchecked_mut

Examples

use bitvec::prelude::*;

let mut data = 0u16;
let bits = data.view_bits_mut::<Lsb0>();

unsafe {
  let mut bit = bits.get_unchecked_mut(1);
  *bit = true;
}
assert_eq!(data, 2);

pub fn as_ptr(&self) -> *const Self[src]

Returns a raw bit-slice pointer to the region.

The caller must ensure that the slice outlives the pointer this function returns, or else it will end up pointing to garbage.

The caller must also ensure that the memory the pointer (non-transitively) points to is only written to if T allows shared mutation, using this pointer or any pointer derived from it. If you need to mutate the contents of the slice, use as_mut_ptr.

Modifying the container (such as BitVec) referenced by this slice may cause its buffer to be reällocated, which would also make any pointers to it invalid.

Original

slice::as_ptr

API Differences

This returns *const BitSlice, which is the equivalent of *const [T] instead of *const T. The pointer encoding used requires more than one CPU word of space to address a single bit, so there is no advantage to removing the length information from the encoded pointer value.

Notes

You cannot use any of the methods in the pointer fundamental type or the core::ptr module on the *_ BitSlice type. This pointer retains the bitvec-specific value encoding, and is incomprehensible by the Rust standard library.

The only thing you can do with this pointer is dereference it.

Examples

use bitvec::prelude::*;

let data = 2u16;
let bits = data.view_bits::<Lsb0>();
let bits_ptr = bits.as_ptr();

for i in 0 .. bits.len() {
  assert_eq!(bits[i], unsafe {
    (&*bits_ptr)[i]
  });
}

pub fn as_mut_ptr(&mut self) -> *mut Self[src]

Returns an unsafe mutable bit-slice pointer to the region.

The caller must ensure that the slice outlives the pointer this function returns, or else it will end up pointing to garbage.

Modifying the container (such as BitVec) referenced by this slice may cause its buffer to be reällocated, which would also make any pointers to it invalid.

Original

slice::as_mut_ptr

API Differences

This returns *mut BitSlice, which is the equivalont of *mut [T] instead of *mut T. The pointer encoding used requires more than one CPU word of space to address a single bit, so there is no advantage to removing the length information from the encoded pointer value.

Notes

You cannot use any of the methods in the pointer fundamental type or the core::ptr module on the *_ BitSlice type. This pointer retains the bitvec-specific value encoding, and is incomprehensible by the Rust standard library.

Examples

use bitvec::prelude::*;

let mut data = 0u16;
let bits = data.view_bits_mut::<Lsb0>();
let bits_ptr = bits.as_mut_ptr();

for i in 0 .. bits.len() {
  unsafe { &mut *bits_ptr }.set(i, i % 2 == 0);
}
assert_eq!(data, 0b0101_0101_0101_0101);

pub fn swap(&mut self, a: usize, b: usize)[src]

Swaps two bits in the slice.

Original

slice::swap

Arguments

  • a: The index of the first bit
  • b: The index of the second bit

Panics

Panics if a or b are out of bounds.

Examples

use bitvec::prelude::*;

let mut data = 2u8;
let bits = data.view_bits_mut::<Lsb0>();
bits.swap(1, 3);
assert_eq!(data, 8);

pub fn reverse(&mut self)[src]

Reverses the order of bits in the slice, in place.

Original

slice::reverse

Examples

use bitvec::prelude::*;

let mut data = 0b1_1001100u8;
let bits = data.view_bits_mut::<Msb0>();
bits[1 ..].reverse();
assert_eq!(data, 0b1_0011001);

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

Notable traits for Iter<'a, O, T>

impl<'a, O, T> Iterator for Iter<'a, O, T> where
    O: 'a + BitOrder,
    T: 'a + BitStore
type Item = <usize as BitSliceIndex<'a, O, T>>::Immut;
[src]

Returns an iterator over the slice.

Original

slice::iter

Examples

use bitvec::prelude::*;

let data = 130u8;
let bits = data.view_bits::<Lsb0>();
let mut iterator = bits.iter();

assert_eq!(iterator.next(), Some(&false));
assert_eq!(iterator.next(), Some(&true));
assert_eq!(iterator.nth(5), Some(&true));
assert_eq!(iterator.next(), None);

pub fn iter_mut(&mut self) -> IterMut<'_, O, T>

Notable traits for IterMut<'a, O, T>

impl<'a, O, T> Iterator for IterMut<'a, O, T> where
    O: 'a + BitOrder,
    T: 'a + BitStore
type Item = <usize as BitSliceIndex<'a, O, T::Alias>>::Mut;
[src]

Returns an iterator that allows modifying each bit.

Original

slice::iter_mut

Examples

use bitvec::prelude::*;

let mut data = 0u8;
let bits = data.view_bits_mut::<Msb0>();
for (idx, mut elem) in bits.iter_mut().enumerate() {
  *elem = idx % 3 == 0;
}
assert_eq!(data, 0b100_100_10);

pub fn windows(&self, size: usize) -> Windows<'_, O, T>

Notable traits for Windows<'a, O, T>

impl<'a, O, T> Iterator for Windows<'a, O, T> where
    O: BitOrder,
    T: 'a + BitStore
type Item = &'a BitSlice<O, T>;
[src]

Returns an iterator over all contiguous windows of length size. The windows overlap. If the slice is shorter than size, the iterator returns no values.

Original

slice::windows

Panics

Panics if size is 0.

Examples

use bitvec::prelude::*;

let data = 0xA5u8;
let bits = data.view_bits::<Msb0>();
let mut iter = bits.windows(6);
assert_eq!(iter.next().unwrap(), &bits[.. 6]);
assert_eq!(iter.next().unwrap(), &bits[1 .. 7]);
assert_eq!(iter.next().unwrap(), &bits[2 ..]);
assert!(iter.next().is_none());

If the slice is shorter than size:

use bitvec::prelude::*;

let bits = BitSlice::<LocalBits, usize>::empty();
let mut iter = bits.windows(1);
assert!(iter.next().is_none());

pub fn chunks(&self, chunk_size: usize) -> Chunks<'_, O, T>

Notable traits for Chunks<'a, O, T>

impl<'a, O, T> Iterator for Chunks<'a, O, T> where
    O: BitOrder,
    T: 'a + BitStore
type Item = &'a BitSlice<O, T>;
[src]

Returns an iterator over chunk_size bits of the slice at a time, starting at the beginning of the slice.

The chunks are slices and do not overlap. If chunk_size does not divide the length of the slice, then the last chunk will not have length chunk_size.

See chunks_exact for a variant of this iterator that returns chunks of always exactly chunk_size bits, and rchunks for the same iterator but starting at the end of the slice.

Original

slice::chunks

Panics

Panics if chunk_size is 0.

Examples

use bitvec::prelude::*;

let data = 0xA5u8;
let bits = data.view_bits::<Lsb0>();
let mut iter = bits.chunks(3);
assert_eq!(iter.next().unwrap(), &bits[.. 3]);
assert_eq!(iter.next().unwrap(), &bits[3 .. 6]);
assert_eq!(iter.next().unwrap(), &bits[6 ..]);
assert!(iter.next().is_none());

pub fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, O, T>

Notable traits for ChunksMut<'a, O, T>

impl<'a, O, T> Iterator for ChunksMut<'a, O, T> where
    O: BitOrder,
    T: 'a + BitStore
type Item = &'a mut BitSlice<O, T::Alias>;
[src]

Returns an iterator over chunk_size bits of the slice at a time, starting at the beginning of the slice.

The chunks are mutable slices, and do not overlap. If chunk_size does not divide the length of the slice, then the last chunk will not have length chunk_size.

See chunks_exact_mut for a variant of this iterator that returns chunks of always exactly chunk_size bits, and rchunks_mut for the same iterator but starting at the end of the slice.

Original

slice::chunks_mut

Panics

Panics if chunk_size is 0.

Examples

use bitvec::prelude::*;

let mut data = 0u8;
let bits = data.view_bits_mut::<Lsb0>();

for (idx, chunk) in bits.chunks_mut(3).enumerate() {
  chunk.set(2 - idx, true);
}
assert_eq!(data, 0b01_010_100);

pub fn chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, O, T>

Notable traits for ChunksExact<'a, O, T>

impl<'a, O, T> Iterator for ChunksExact<'a, O, T> where
    O: BitOrder,
    T: 'a + BitStore
type Item = &'a BitSlice<O, T>;
[src]

Returns an iterator over chunk_size bits of the slice at a time, starting at the beginning of the slice.

The chunks are slices and do not overlap. If chunk_size does not divide the length of the slice, then the last up to chunk_size-1 bits will be omitted and can be retrieved from the remainder function of the iterator.

Due to each chunk having exactly chunk_size bits, the compiler may optimize the resulting code better than in the case of chunks.

See chunks for a variant of this iterator that also returns the remainder as a smaller chunk, and rchunks_exact for the same iterator but starting at the end of the slice.

Original

slice::chunks_exact

Panics

Panics if chunk_size is 0.

Examples

use bitvec::prelude::*;

let data = 0xA5u8;
let bits = data.view_bits::<Lsb0>();
let mut iter = bits.chunks_exact(3);
assert_eq!(iter.next().unwrap(), &bits[.. 3]);
assert_eq!(iter.next().unwrap(), &bits[3 .. 6]);
assert!(iter.next().is_none());
assert_eq!(iter.remainder(), &bits[6 ..]);

pub fn chunks_exact_mut(
    &mut self,
    chunk_size: usize
) -> ChunksExactMut<'_, O, T>

Notable traits for ChunksExactMut<'a, O, T>

impl<'a, O, T> Iterator for ChunksExactMut<'a, O, T> where
    O: BitOrder,
    T: 'a + BitStore
type Item = &'a mut BitSlice<O, T::Alias>;
[src]

Returns an iterator over chunk_size bits of the slice at a time, starting at the beginning of the slice.

The chunks are mutable slices, and do not overlap. If chunk_size does not divide the beginning length of the slice, then the last up to chunk_size-1 bits will be omitted and can be retrieved from the into_remainder function of the iterator.

Due to each chunk having exactly chunk_size bits, the compiler may optimize the resulting code better than in the case of chunks_mut.

See chunks_mut for a variant of this iterator that also returns the remainder as a smaller chunk, and rchunks_exact_mut for the same iterator but starting at the end of the slice.

Original

slice::chunks_exact_mut

Panics

Panics if chunk_size is 0.

Examples

use bitvec::prelude::*;

let mut data = 0u8;
let bits = data.view_bits_mut::<Lsb0>();

for (idx, chunk) in bits.chunks_exact_mut(3).enumerate() {
  chunk.set(idx, true);
}
assert_eq!(data, 0b00_010_001);

pub fn rchunks(&self, chunk_size: usize) -> RChunks<'_, O, T>

Notable traits for RChunks<'a, O, T>

impl<'a, O, T> Iterator for RChunks<'a, O, T> where
    O: BitOrder,
    T: 'a + BitStore
type Item = &'a BitSlice<O, T>;
[src]

Returns an iterator over chunk_size bits of the slice at a time, starting at the end of the slice.

The chunks are slices and do not overlap. If chunk_size does not divide the length of the slice, then the last chunk will not have length chunk_size.

See rchunks_exact for a variant of this iterator that returns chunks of always exactly chunk_size bits, and chunks for the same iterator but starting at the beginning of the slice.

Original

slice::rchunks

Panics

Panics if chunk_size is 0.

Examples

use bitvec::prelude::*;

let data = 0xA5u8;
let bits = data.view_bits::<Lsb0>();
let mut iter = bits.rchunks(3);
assert_eq!(iter.next().unwrap(), &bits[5 ..]);
assert_eq!(iter.next().unwrap(), &bits[2 .. 5]);
assert_eq!(iter.next().unwrap(), &bits[.. 2]);
assert!(iter.next().is_none());

pub fn rchunks_mut(&mut self, chunk_size: usize) -> RChunksMut<'_, O, T>

Notable traits for RChunksMut<'a, O, T>

impl<'a, O, T> Iterator for RChunksMut<'a, O, T> where
    O: BitOrder,
    T: 'a + BitStore
type Item = &'a mut BitSlice<O, T::Alias>;
[src]

Returns an iterator over chunk_size bits of the slice at a time, starting at the end of the slice.

The chunks are mutable slices, and do not overlap. If chunk_size does not divide the length of the slice, then the last chunk will not have length chunk_size.

See rchunks_exact_mut for a variant of this iterator that returns chunks of always exactly chunk_size bits, and chunks_mut for the same iterator but starting at the beginning of the slice.

Original

slice::rchunks_mut

Panics

Panics if chunk_size is 0.

Examples

use bitvec::prelude::*;

let mut data = 0u8;
let bits = data.view_bits_mut::<Lsb0>();

for (idx, chunk) in bits.rchunks_mut(3).enumerate() {
  chunk.set(2 - idx, true);
}
assert_eq!(data, 0b100_010_01);

pub fn rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, O, T>

Notable traits for RChunksExact<'a, O, T>

impl<'a, O, T> Iterator for RChunksExact<'a, O, T> where
    O: BitOrder,
    T: 'a + BitStore
type Item = &'a BitSlice<O, T>;
[src]

Returns an iterator over chunk_size bits of the slice at a time, starting at the end of the slice.

The chunks are slices and do not overlap. If chunk_size does not divide the length of the slice, then the last up to chunk_size-1 bits will be omitted and can be retrieved from the remainder function of the iterator.

Due to each chunk having exactly chunk_size bits, the compiler can often optimize the resulting code better than in the case of chunks.

See rchunks for a variant of this iterator that also returns the remainder as a smaller chunk, and chunks_exact for the same iterator but starting at the beginning of the slice.

Original

slice::rchunks_exact

Panics

Panics if chunk_size is 0.

Examples

use bitvec::prelude::*;

let data = 0xA5u8;
let bits = data.view_bits::<Lsb0>();
let mut iter = bits.rchunks_exact(3);
assert_eq!(iter.next().unwrap(), &bits[5 ..]);
assert_eq!(iter.next().unwrap(), &bits[2 .. 5]);
assert!(iter.next().is_none());
assert_eq!(iter.remainder(), &bits[.. 2]);

pub fn rchunks_exact_mut(
    &mut self,
    chunk_size: usize
) -> RChunksExactMut<'_, O, T>

Notable traits for RChunksExactMut<'a, O, T>

impl<'a, O, T> Iterator for RChunksExactMut<'a, O, T> where
    O: BitOrder,
    T: 'a + BitStore
type Item = &'a mut BitSlice<O, T::Alias>;
[src]

Returns an iterator over chunk_size bits of the slice at a time, starting at the end of the slice.

The chunks are mutable slices, and do not overlap. If chunk_size does not divide the length of the slice, then the last up to chunk_size-1 bits will be omitted and can be retrieved from the into_remainder function of the iterator.

Due to each chunk having exactly chunk_size bits, the compiler can often optimize the resulting code better than in the case of chunks_mut.

See rchunks_mut for a variant of this iterator that also returns the remainder as a smaller chunk, and chunks_exact_mut for the same iterator but starting at the beginning of the slice.

Panics

Panics if chunk_size is 0.

Examples

use bitvec::prelude::*;

let mut data = 0u8;
let bits = data.view_bits_mut::<Lsb0>();

for (idx, chunk) in bits.rchunks_exact_mut(3).enumerate() {
  chunk.set(idx, true);
}
assert_eq!(data, 0b001_010_00);

pub fn split_at(&self, mid: usize) -> (&Self, &Self)[src]

Divides one slice into two at an index.

The first will contain all indices from [0, mid) (excluding the index mid itself) and the second will contain all indices from [mid, len) (excluding the index len itself).

Original

slice::split_at

Panics

Panics if mid > len.

Examples

use bitvec::prelude::*;

let data = 0xC3u8;
let bits = data.view_bits::<LocalBits>();

let (left, right) = bits.split_at(0);
assert!(left.is_empty());
assert_eq!(right, bits);

let (left, right) = bits.split_at(2);
assert_eq!(left, &bits[.. 2]);
assert_eq!(right, &bits[2 ..]);

let (left, right) = bits.split_at(8);
assert_eq!(left, bits);
assert!(right.is_empty());

pub fn split_at_mut(
    &mut self,
    mid: usize
) -> (&mut BitSlice<O, T::Alias>, &mut BitSlice<O, T::Alias>)
[src]

Divides one mutable slice into two at an index.

The first will contain all indices from [0, mid) (excluding the index mid itself) and the second will contain all indices from [mid, len) (excluding the index len itself).

Original

slice::split_at_mut

API Differences

Because the partition point mid is permitted to occur in the interior of a memory element T, this method is required to mark the returned slices as being to aliased memory. This marking ensures that writes to the covered memory use the appropriate synchronization behavior of your build to avoid data races – by default, this makes all writes atomic; on builds with the atomic feature disabled, this uses Cells and forbids the produced subslices from leaving the current thread.

See the BitStore documentation for more information.

Panics

Panics if mid > len.

Examples

use bitvec::prelude::*;

let mut data = 0u8;
let bits = data.view_bits_mut::<Msb0>();
// scoped to restrict the lifetime of the borrows
{
  let (left, right) = bits.split_at_mut(3);
  *left.get_mut(1).unwrap() = true;
  *right.get_mut(2).unwrap() = true;
}
assert_eq!(data, 0b010_00100);

pub fn split<F>(&self, pred: F) -> Split<'_, O, T, F>

Notable traits for Split<'a, O, T, P>

impl<'a, O, T, P> Iterator for Split<'a, O, T, P> where
    O: 'a + BitOrder,
    T: 'a + BitStore,
    P: FnMut(usize, &bool) -> bool
type Item = &'a BitSlice<O, T>;
where
    F: FnMut(usize, &bool) -> bool
[src]

Returns an iterator over subslices separated by bits that match pred. The matched bit is not contained in the subslices.

Original

slice::split

API Differences

In order to allow more than one bit of information for the split decision, the predicate receives the index of each bit, as well as its value.

Examples

use bitvec::prelude::*;

let data = 0b01_001_000u8;
let bits = data.view_bits::<Msb0>();
let mut iter = bits.split(|_pos, bit| *bit);

assert_eq!(iter.next().unwrap(), &bits[.. 1]);
assert_eq!(iter.next().unwrap(), &bits[2 .. 4]);
assert_eq!(iter.next().unwrap(), &bits[5 ..]);
assert!(iter.next().is_none());

If the first bit is matched, an empty slice will be the first item returned by the iterator. Similarly, if the last element in the slice is matched, an empty slice will be the last item returned by the iterator:

use bitvec::prelude::*;

let data = 1u8;
let bits = data.view_bits::<Msb0>();
let mut iter = bits.split(|_pos, bit| *bit);

assert_eq!(iter.next().unwrap(), &bits[.. 7]);
assert!(iter.next().unwrap().is_empty());
assert!(iter.next().is_none());

If two matched bits are directly adjacent, an empty slice will be present between them:

use bitvec::prelude::*;

let data = 0b001_100_00u8;
let bits = data.view_bits::<Msb0>();
let mut iter = bits.split(|pos, bit| *bit);

assert_eq!(iter.next().unwrap(), &bits[0 .. 2]);
assert!(iter.next().unwrap().is_empty());
assert_eq!(iter.next().unwrap(), &bits[4 .. 8]);
assert!(iter.next().is_none());

pub fn split_mut<F>(&mut self, pred: F) -> SplitMut<'_, O, T, F>

Notable traits for SplitMut<'a, O, T, P>

impl<'a, O, T, P> Iterator for SplitMut<'a, O, T, P> where
    O: 'a + BitOrder,
    T: 'a + BitStore,
    P: FnMut(usize, &bool) -> bool
type Item = &'a mut BitSlice<O, T::Alias>;
where
    F: FnMut(usize, &bool) -> bool
[src]

Returns an iterator over mutable subslices separated by bits that match pred. The matched bit is not contained in the subslices.

Original

slice::split_mut

API Differences

In order to allow more than one bit of information for the split decision, the predicate receives the index of each bit, as well as its value.

Examples

use bitvec::prelude::*;

let mut data = 0b001_000_10u8;
let bits = data.view_bits_mut::<Msb0>();

for group in bits.split_mut(|_pos, bit| *bit) {
  *group.get_mut(0).unwrap() = true;
}
assert_eq!(data, 0b101_100_11);

pub fn rsplit<F>(&self, pred: F) -> RSplit<'_, O, T, F>

Notable traits for RSplit<'a, O, T, P>

impl<'a, O, T, P> Iterator for RSplit<'a, O, T, P> where
    O: 'a + BitOrder,
    T: 'a + BitStore,
    P: FnMut(usize, &bool) -> bool
type Item = &'a BitSlice<O, T>;
where
    F: FnMut(usize, &bool) -> bool
[src]

Returns an iterator over subslices separated by bits that match pred, starting at the end of the slice and working backwards. The matched bit is not contained in the subslices.

Original

slice::rsplit

API Differences

In order to allow more than one bit of information for the split decision, the predicate receives the index of each bit, as well as its value.

Examples

use bitvec::prelude::*;

let data = 0b0001_0000u8;
let bits = data.view_bits::<Msb0>();
let mut iter = bits.rsplit(|_pos, bit| *bit);

assert_eq!(iter.next().unwrap(), &bits[4 ..]);
assert_eq!(iter.next().unwrap(), &bits[.. 3]);
assert!(iter.next().is_none());

As with split(), if the first or last bit is matched, an empty slice will be the first (or last) item returned by the iterator.

use bitvec::prelude::*;

let data = 0b1001_0001u8;
let bits = data.view_bits::<Msb0>();
let mut iter = bits.rsplit(|_pos, bit| *bit);
assert!(iter.next().unwrap().is_empty());
assert_eq!(iter.next().unwrap(), &bits[4 .. 7]);
assert_eq!(iter.next().unwrap(), &bits[1 .. 3]);
assert!(iter.next().unwrap().is_empty());
assert!(iter.next().is_none());

pub fn rsplit_mut<F>(&mut self, pred: F) -> RSplitMut<'_, O, T, F>

Notable traits for RSplitMut<'a, O, T, P>

impl<'a, O, T, P> Iterator for RSplitMut<'a, O, T, P> where
    O: 'a + BitOrder,
    T: 'a + BitStore,
    P: FnMut(usize, &bool) -> bool
type Item = &'a mut BitSlice<O, T::Alias>;
where
    F: FnMut(usize, &bool) -> bool
[src]

Returns an iterator over mutable subslices separated by bits that match pred, starting at the end of the slice and working backwards. The matched bit is not contained in the subslices.

Original

slice::rsplit_mut

API Differences

In order to allow more than one bit of information for the split decision, the predicate receives the index of each bit, as well as its value.

Examples

use bitvec::prelude::*;

let mut data = 0b001_000_10u8;
let bits = data.view_bits_mut::<Msb0>();

for group in bits.rsplit_mut(|_pos, bit| *bit) {
  *group.get_mut(0).unwrap() = true;
}
assert_eq!(data, 0b101_100_11);

pub fn splitn<F>(&self, n: usize, pred: F) -> SplitN<'_, O, T, F>

Notable traits for SplitN<'a, O, T, P>

impl<'a, O, T, P> Iterator for SplitN<'a, O, T, P> where
    O: 'a + BitOrder,
    T: 'a + BitStore,
    P: FnMut(usize, &bool) -> bool
type Item = <Split<'a, O, T, P> as Iterator>::Item;
where
    F: FnMut(usize, &bool) -> bool
[src]

Returns an iterator over subslices separated by bits that match pred, limited to returning at most n items. The matched bit is not contained in the subslices.

The last item returned, if any, will contain the remainder of the slice.

Original

slice::splitn

API Differences

In order to allow more than one bit of information for the split decision, the predicate receives the index of each bit, as well as its value.

Examples

use bitvec::prelude::*;

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

for group in bits.splitn(2, |pos, _bit| pos % 3 == 2) {
  println!("{}", group.len());
}
//  2
//  5

pub fn splitn_mut<F>(&mut self, n: usize, pred: F) -> SplitNMut<'_, O, T, F>

Notable traits for SplitNMut<'a, O, T, P>

impl<'a, O, T, P> Iterator for SplitNMut<'a, O, T, P> where
    O: 'a + BitOrder,
    T: 'a + BitStore,
    P: FnMut(usize, &bool) -> bool
type Item = <SplitMut<'a, O, T, P> as Iterator>::Item;
where
    F: FnMut(usize, &bool) -> bool
[src]

Returns an iterator over subslices separated by bits that match pred, limited to returning at most n items. The matched element is not contained in the subslices.

The last item returned, if any, will contain the remainder of the slice.

Original

slice::splitn_mut

API Differences

In order to allow more than one bit of information for the split decision, the predicate receives the index of each bit, as well as its value.

Examples

use bitvec::prelude::*;

let mut data = 0b001_000_10u8;
let bits = data.view_bits_mut::<Msb0>();

for group in bits.splitn_mut(2, |_pos, bit| *bit) {
  *group.get_mut(0).unwrap() = true;
}
assert_eq!(data, 0b101_100_10);

pub fn rsplitn<F>(&self, n: usize, pred: F) -> RSplitN<'_, O, T, F>

Notable traits for RSplitN<'a, O, T, P>

impl<'a, O, T, P> Iterator for RSplitN<'a, O, T, P> where
    O: 'a + BitOrder,
    T: 'a + BitStore,
    P: FnMut(usize, &bool) -> bool
type Item = <RSplit<'a, O, T, P> as Iterator>::Item;
where
    F: FnMut(usize, &bool) -> bool
[src]

Returns an iterator over subslices separated by bits that match pred limited to returining at most n items. This starts at the end of the slice and works backwards. The matched bit is not contained in the subslices.

The last item returned, if any, will contain the remainder of the slice.

Original

slice::rsplitn

API Differences

In order to allow more than one bit of information for the split decision, the predicate receives the index of each bit, as well as its value.

Examples

use bitvec::prelude::*;

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

for group in bits.rsplitn(2, |pos, _bit| pos % 3 == 2) {
  println!("{}", group.len());
}
//  2
//  5

pub fn rsplitn_mut<F>(&mut self, n: usize, pred: F) -> RSplitNMut<'_, O, T, F>

Notable traits for RSplitNMut<'a, O, T, P>

impl<'a, O, T, P> Iterator for RSplitNMut<'a, O, T, P> where
    O: 'a + BitOrder,
    T: 'a + BitStore,
    P: FnMut(usize, &bool) -> bool
type Item = <RSplitMut<'a, O, T, P> as Iterator>::Item;
where
    F: FnMut(usize, &bool) -> bool
[src]

Returns an iterator over subslices separated by bits that match pred limited to returning at most n items. This starts at the end of the slice and works backwards. The matched bit is not contained in the subslices.

The last item returned, if any, will contain the remainder of the slice.

Original

slice::rsplitn_mut

API Differences

In order to allow more than one bit of information for the split decision, the predicate receives the index of each bit, as well as its value.

Examples

use bitvec::prelude::*;

let mut data = 0b001_000_10u8;
let bits = data.view_bits_mut::<Msb0>();

for group in bits.rsplitn_mut(2, |_pos, bit| *bit) {
  *group.get_mut(0).unwrap() = true;
}
assert_eq!(data, 0b101_000_11);

pub fn contains<O2, T2>(&self, x: &BitSlice<O2, T2>) -> bool where
    O2: BitOrder,
    T2: BitStore
[src]

Returns true if the slice contains a subslice that matches the given span.

Original

slice::contains

API Differences

This searches for a matching subslice (allowing different type parameters) rather than for a specific bit. Searching for a contained element with a given value is not as useful on a collection of bool.

Furthermore, BitSlice defines any and not_all, which are optimized searchers for any true or false bit, respectively, in a sequence.

Examples

use bitvec::prelude::*;

let data = 0b0101_1010u8;
let bits_msb = data.view_bits::<Msb0>();
let bits_lsb = data.view_bits::<Lsb0>();
assert!(bits_msb.contains(&bits_lsb[1 .. 5]));

This example uses a palindrome pattern to demonstrate that the slice being searched for does not need to have the same type parameters as the slice being searched.

pub fn starts_with<O2, T2>(&self, needle: &BitSlice<O2, T2>) -> bool where
    O2: BitOrder,
    T2: BitStore
[src]

Returns true if needle is a prefix of the slice.

Original

slice::starts_with

Examples

use bitvec::prelude::*;

let data = 0b0100_1011u8;
let haystack = data.view_bits::<Msb0>();
let needle = &data.view_bits::<Lsb0>()[2 .. 5];
assert!(haystack.starts_with(&needle[.. 2]));
assert!(haystack.starts_with(needle));
assert!(!haystack.starts_with(&haystack[2 .. 4]));

Always returns true if needle is an empty slice:

use bitvec::prelude::*;

let empty = BitSlice::<LocalBits, usize>::empty();
assert!(0u8.view_bits::<LocalBits>().starts_with(empty));
assert!(empty.starts_with(empty));

pub fn ends_with<O2, T2>(&self, needle: &BitSlice<O2, T2>) -> bool where
    O2: BitOrder,
    T2: BitStore
[src]

Returns true if needle is a suffix of the slice.

Original

slice::ends_with

Examples

use bitvec::prelude::*;

let data = 0b0100_1011u8;
let haystack = data.view_bits::<Lsb0>();
let needle = &data.view_bits::<Msb0>()[3 .. 6];
assert!(haystack.ends_with(&needle[1 ..]));
assert!(haystack.ends_with(needle));
assert!(!haystack.ends_with(&haystack[2 .. 4]));

Always returns true if needle is an empty slice:

use bitvec::prelude::*;

let empty = BitSlice::<LocalBits, usize>::empty();
assert!(0u8.view_bits::<LocalBits>().ends_with(empty));
assert!(empty.ends_with(empty));

pub fn rotate_left(&mut self, by: usize)[src]

Rotates the slice in-place such that the first by bits of the slice move to the end while the last self.len() - by bits move to the front. After calling rotate_left, the bit previously at index by will become the first bit in the slice.

Original

slice::rotate_left

Panics

This function will panic if by is greater than the length of the slice. Note that by == self.len() does not panic and is a no-op rotation.

Complexity

Takes linear (in self.len()) time.

Performance

While this is faster than the equivalent rotation on [bool], it is slower than a handcrafted partial-element rotation on [T]. Because of the support for custom orderings, and the lack of specialization, this method can only accelerate by reducing the number of loop iterations performed on the slice body, and cannot accelerate by using shift-mask instructions to move multiple bits in one operation.

Examples

use bitvec::prelude::*;
let mut data = 0xF0u8;
let bits = data.view_bits_mut::<Msb0>();
bits.rotate_left(2);
assert_eq!(data, 0xC3);

Rotating a subslice:

use bitvec::prelude::*;

let mut data = 0xF0u8;
let bits = data.view_bits_mut::<Msb0>();
bits[1 .. 5].rotate_left(1);
assert_eq!(data, 0b1_1101_000);

pub fn rotate_right(&mut self, by: usize)[src]

Rotates the slice in-place such that the first self.len() - by bits of the slice move to the end while the last by bits move to the front. After calling rotate_right, the bit previously at index self.len() - by will become the first bit in the slice.

Original

slice::rotate_right

Panics

This function will panic if by is greater than the length of the slice. Note that by == self.len() does not panic and is a no-op rotation.

Complexity

Takes linear (in self.len()) time.

Performance

While this is faster than the equivalent rotation on [bool], it is slower than a handcrafted partial-element rotation on [T]. Because of the support for custom orderings, and the lack of specialization, this method can only accelerate by reducing the number of loop iterations performed on the slice body, and cannot accelerate by using shift-mask instructions to move multiple bits in one operation.

Examples

use bitvec::prelude::*;

let mut data = 0xF0u8;
let bits = data.view_bits_mut::<Msb0>();
bits.rotate_right(2);
assert_eq!(data, 0x3C);

Rotate a subslice:

use bitvec::prelude::*;

let mut data = 0xF0u8;
let bits = data.view_bits_mut::<Msb0>();
bits[1 .. 5].rotate_right(1);
assert_eq!(data, 0b1_0111_000);

pub fn clone_from_bitslice<O2, T2>(&mut self, src: &BitSlice<O2, T2>) where
    O2: BitOrder,
    T2: BitStore
[src]

Copies the bits from src into self.

The length of src must be the same as self.

Original

slice::clone_from_slice

API Differences

This method is renamed, as it takes a bit slice rather than an element slice.

Panics

This function will panic if the two slices have different lengths.

Examples

Cloning two bits from a slice into another:

use bitvec::prelude::*;

let mut data = 0u8;
let bits = data.view_bits_mut::<Msb0>();
let src = 0x0Fu16.view_bits::<Lsb0>();
bits[.. 2].clone_from_bitslice(&src[2 .. 4]);
assert_eq!(data, 0xC0);

Rust enforces that there can only be one mutable reference with no immutable references to a particular piece of data in a particular scope. Because of this, attempting to use clone_from_bitslice on a single slice will result in a compile failure:

This example deliberately fails to compile
use bitvec::prelude::*;

let mut data = 3u8;
let bits = data.view_bits_mut::<Msb0>();
bits[.. 2].clone_from_bitslice(&bits[6 ..]);

To work around this, we can use split_at_mut to create two distinct sub-slices from a slice:

use bitvec::prelude::*;

let mut data = 3u8;
let bits = data.view_bits_mut::<Msb0>();
let (head, tail) = bits.split_at_mut(4);
head.clone_from_bitslice(tail);
assert_eq!(data, 0x33);

pub fn copy_from_bitslice(&mut self, src: &Self)[src]

Copies all bits from src into self.

The length of src must be the same as self.

Original

slice::copy_from_slice

API Differences

This method is renamed, as it takes a bit slice rather than an element slice.

This is unable to guarantee a strictly faster copy behavior than clone_from_bitslice. In the future, the implementation may specialize, as the language allows.

Panics

This function will panic if the two slices have different lengths.

Examples

Copying two bits from a slice into another:

pub fn copy_within<R>(&mut self, src: R, dest: usize) where
    R: RangeBounds<usize>, 
[src]

Copies bits from one part of the slice to another part of itself.

src is the range within self to copy from. dest is the starting index of the range within self to copy to, which will have the same length as src. The two ranges may overlap. The ends of the two ranges must be less than or equal to self.len().

Original

slice::copy_within

Panics

This function will panic if either range exceeds the end of the slice, or if the end of src is before the start.

Examples

Copying four bytes within a slice:

use bitvec::prelude::*;

let mut data = 0x07u8;
let bits = data.view_bits_mut::<Msb0>();

bits.copy_within(5 .., 0);

assert_eq!(data, 0xE7);

pub fn swap_with_bitslice<O2, T2>(&mut self, other: &mut BitSlice<O2, T2>) where
    O2: BitOrder,
    T2: BitStore
[src]

Swaps all bits in self with those in other.

The length of other must be the same as self.

Original

slice::swap_with_slice

API Differences

This method is renamed, as it takes a bit slice rather than an element slice.

Panics

This function will panic if the two slices have different lengths.

Examples

use bitvec::prelude::*;

let mut one = [0xA5u8, 0x69];
let mut two = 0x1234u16;
let one_bits = one.view_bits_mut::<Msb0>();
let two_bits = two.view_bits_mut::<Lsb0>();

one_bits.swap_with_bitslice(two_bits);

assert_eq!(one, [0x2C, 0x48]);
assert_eq!(two, 0x96A5);

pub unsafe fn align_to<U>(&self) -> (&Self, &BitSlice<O, U>, &Self) where
    U: BitStore
[src]

Transmute the bitslice to a bitslice of another type, ensuring alignment of the types is maintained.

This method splits the bitslice into three distinct bitslices: prefix, correctly aligned middle bitslice of a new type, and the suffix bitslice. The method may make the middle bitslice the greatest length possible for a given type and input bitslice, but only your algorithm's performance should depend on that, not its correctness. It is permissible for all of the input data to be returned as the prefix or suffix bitslice.

Original

slice::align_to

API Differences

Type U is required to have the same type family as type T. Whatever T is of the fundamental integers, atomics, or Cell wrappers, U must be a different width in the same family. Changing the type family with this method is unsound and strictly forbidden. Unfortunately, it cannot be guaranteed by this function, so you are required to abide by this limitation.

Safety

This method is essentially a transmute with respect to the elements in the returned middle bitslice, so all the usual caveats pertaining to transmute::<T, U> also apply here.

Examples

Basic usage:

use bitvec::prelude::*;

unsafe {
  let bytes: [u8; 7] = [1, 2, 3, 4, 5, 6, 7];
  let bits = bytes.view_bits::<LocalBits>();
  let (prefix, shorts, suffix) = bits.align_to::<u16>();
  match prefix.len() {
    0 => {
      assert_eq!(shorts, bits[.. 48]);
      assert_eq!(suffix, bits[48 ..]);
    },
    8 => {
      assert_eq!(prefix, bits[.. 8]);
      assert_eq!(shorts, bits[8 ..]);
    },
    _ => unreachable!("This case will not occur")
  }
}

pub unsafe fn align_to_mut<U>(
    &mut self
) -> (&mut Self, &mut BitSlice<O, U>, &mut Self) where
    U: BitStore
[src]

Transmute the bitslice to a bitslice of another type, ensuring alignment of the types is maintained.

This method splits the bitslice into three distinct bitslices: prefix, correctly aligned middle bitslice of a new type, and the suffix bitslice. The method may make the middle bitslice the greatest length possible for a given type and input bitslice, but only your algorithm's performance should depend on that, not its correctness. It is permissible for all of the input data to be returned as the prefix or suffix bitslice.

Original

slice::align_to

API Differences

Type U is required to have the same type family as type T. Whatever T is of the fundamental integers, atomics, or Cell wrappers, U must be a different width in the same family. Changing the type family with this method is unsound and strictly forbidden. Unfortunately, it cannot be guaranteed by this function, so you are required to abide by this limitation.

Safety

This method is essentially a transmute with respect to the elements in the returned middle bitslice, so all the usual caveats pertaining to transmute::<T, U> also apply here.

Examples

Basic usage:

use bitvec::prelude::*;

unsafe {
  let mut bytes: [u8; 7] = [1, 2, 3, 4, 5, 6, 7];
  let bits = bytes.view_bits_mut::<LocalBits>();
  let (prefix, shorts, suffix) = bits.align_to_mut::<u16>();
  //  same access and behavior as in `align_to`
}

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

Notable traits for BitVec<O, T>

impl<O, T> Write for BitVec<O, T> where
    O: BitOrder,
    T: BitStore,
    BitSlice<O, T::Alias>: BitField
[src]

Copies self into a new BitVec.

Original

slice::to_vec

Examples

use bitvec::prelude::*;

let bits = bits![0, 1, 0, 1];
let bv = bits.to_bitvec();
assert_eq!(bits, bv);

pub fn repeat(&self, n: usize) -> BitVec<O, T>

Notable traits for BitVec<O, T>

impl<O, T> Write for BitVec<O, T> where
    O: BitOrder,
    T: BitStore,
    BitSlice<O, T::Alias>: BitField
where
    O: BitOrder,
    T: BitStore
[src]

Creates a vector by repeating a slice n times.

Original

slice::repeat

Panics

This function will panic if the capacity would overflow.

Examples

Basic usage:

use bitvec::prelude::*;

assert_eq!(bits![0, 1].repeat(3), bits![0, 1, 0, 1, 0, 1]);

A panic upon overflow:

This example panics
use bitvec::prelude::*;

// this will panic at runtime
bits![0, 1].repeat(BitSlice::<LocalBits, usize>::MAX_BITS);

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

Sets the bit value at the given position.

Parameters

  • &mut self
  • index: The bit index to set. It must be in the range 0 .. self.len().
  • value: The value to be set, true for 1 and false for 0.

Effects

If index is valid, then the bit to which it refers is set to value.

Panics

This method panics if index is outside the slice domain.

Examples

use bitvec::prelude::*;

let mut data = 0u8;
let bits = data.view_bits_mut::<Msb0>();

assert!(!bits.get(7).unwrap());
bits.set(7, true);
assert!(bits.get(7).unwrap());
assert_eq!(data, 1);

This example panics when it attempts to set a bit that is out of bounds.

This example panics
use bitvec::prelude::*;

let bits = BitSlice::<LocalBits, usize>::empty_mut();
bits.set(0, false);

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

Sets a bit at an index, without checking boundary conditions.

This is generally not recommended; use with caution! For a safe alternative, see set.

Parameters

  • &mut self
  • index: The bit index to set. It must be in the range 0 .. self.len(). It will not be checked.

Effects

The bit at index is set to value.

Safety

This method is not safe. It performs raw pointer arithmetic to seek from the start of the slice to the requested index, and set the bit there. It does not inspect the length of self, and it is free to perform out-of-bounds memory write access.

Use this method only when you have already performed the bounds check, and can guarantee that the call occurs with a safely in-bounds index.

Examples

This example uses a bit slice of length 2, and demonstrates out-of-bounds access to the last bit in the element.

use bitvec::prelude::*;

let mut data = 0u8;
let bits = &mut data.view_bits_mut::<Msb0>()[2 .. 4];

assert_eq!(bits.len(), 2);
unsafe {
  bits.set_unchecked(5, true);
}
assert_eq!(data, 1);

pub fn all(&self) -> bool[src]

Tests if all bits in the slice domain are set (logical ).

Truth Table

0 0 => 0
0 1 => 0
1 0 => 0
1 1 => 1

Parameters

  • &self

Returns

Whether all bits in the slice domain are set. The empty slice returns true.

Examples

use bitvec::prelude::*;

let bits = 0xFDu8.view_bits::<Msb0>();
assert!(bits[.. 4].all());
assert!(!bits[4 ..].all());

pub fn any(&self) -> bool[src]

Tests if any bit in the slice is set (logical ).

Truth Table

0 0 => 0
0 1 => 1
1 0 => 1
1 1 => 1

Parameters

  • &self

Returns

Whether any bit in the slice domain is set. The empty slice returns false.

Examples

use bitvec::prelude::*;

let bits = 0x40u8.view_bits::<Msb0>();
assert!(bits[.. 4].any());
assert!(!bits[4 ..].any());

pub fn not_all(&self) -> bool[src]

Tests if any bit in the slice is unset (logical ¬∧).

Truth Table

0 0 => 1
0 1 => 1
1 0 => 1
1 1 => 0

Parameters

  • `&self

Returns

Whether any bit in the slice domain is unset.

Examples

use bitvec::prelude::*;

let bits = 0xFDu8.view_bits::<Msb0>();
assert!(!bits[.. 4].not_all());
assert!(bits[4 ..].not_all());

pub fn not_any(&self) -> bool[src]

Tests if all bits in the slice are unset (logical ¬∨).

Truth Table

0 0 => 1
0 1 => 0
1 0 => 0
1 1 => 0

Parameters

  • &self

Returns

Whether all bits in the slice domain are unset.

Examples

use bitvec::prelude::*;

let bits = 0x40u8.view_bits::<Msb0>();
assert!(!bits[.. 4].not_any());
assert!(bits[4 ..].not_any());

pub fn some(&self) -> bool[src]

Tests whether the slice has some, but not all, bits set and some, but not all, bits unset.

This is false if either .all or .not_any are true.

Truth Table

0 0 => 0
0 1 => 1
1 0 => 1
1 1 => 0

Parameters

  • &self

Returns

Whether the slice domain has mixed content. The empty slice returns false.

Examples

use bitvec::prelude::*;

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

assert!(!bits[.. 3].some());
assert!(!bits[3 .. 6].some());
assert!(bits.some());

pub fn count_ones(&self) -> usize[src]

Returns the number of ones in the memory region backing self.

Parameters

  • &self

Returns

The number of high bits in the slice domain.

Examples

Basic usage:

use bitvec::prelude::*;

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

assert_eq!(bits[.. 4].count_ones(), 4);
assert_eq!(bits[4 ..].count_ones(), 0);

pub fn count_zeros(&self) -> usize[src]

Returns the number of zeros in the memory region backing self.

Parameters

  • &self

Returns

The number of low bits in the slice domain.

Examples

Basic usage:

use bitvec::prelude::*;

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

assert_eq!(bits[.. 4].count_zeros(), 0);
assert_eq!(bits[4 ..].count_zeros(), 4);

pub fn set_all(&mut self, value: bool)[src]

Sets all bits in the slice to a value.

Parameters

  • &mut self
  • value: The bit value to which all bits in the slice will be set.

Examples

use bitvec::prelude::*;

let mut src = 0u8;
let bits = src.view_bits_mut::<Msb0>();
bits[2 .. 6].set_all(true);
assert_eq!(bits.as_slice(), &[0b0011_1100]);
bits[3 .. 5].set_all(false);
assert_eq!(bits.as_slice(), &[0b0010_0100]);
bits[.. 1].set_all(true);
assert_eq!(bits.as_slice(), &[0b1010_0100]);

pub fn for_each<F>(&mut self, func: F) where
    F: FnMut(usize, bool) -> bool
[src]

Applies a function to each bit in the slice.

BitSlice cannot implement IndexMut, as it cannot manifest &mut bool references, and the BitMut proxy reference has an unavoidable overhead. This method bypasses both problems, by applying a function to each pair of index and value in the slice, without constructing a proxy reference.

Parameters

  • &mut self
  • func: A function which receives two arguments, index: usize and value: bool, and returns a bool.

Effects

For each index in the slice, the result of invoking func with the index number and current bit value is written into the slice.

Examples

use bitvec::prelude::*;

let mut data = 0u8;
let bits = data.view_bits_mut::<Msb0>();
bits.for_each(|idx, _bit| idx % 3 == 0);
assert_eq!(data, 0b100_100_10);

pub fn as_slice(&self) -> &[T][src]

Accesses the total backing storage of the BitSlice, as a slice of its elements.

This method produces a slice over all the memory elements it touches, using the current storage parameter. This is safe to do, as any events that would create an aliasing view into the elements covered by the returned slice will also have caused the slice to use its alias-aware type.

Parameters

  • &self

Returns

A view of the entire memory region this slice covers, including the edge elements.

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

Views the wholly-filled elements of the BitSlice.

This will not include partially-owned edge elements, as they may be aliased by other handles. To gain access to all elements that the BitSlice region covers, use one of the following:

  • .as_slice produces a shared slice over all elements, marked aliased as appropriate.
  • .domain produces a view describing each component of the region, marking only the contended edges as aliased and the uncontended interior as unaliased.

Parameters

  • &self

Returns

A slice of all the wholly-filled elements in the BitSlice backing storage.

Examples

use bitvec::prelude::*;

let data = [1u8, 66];
let bits = data.view_bits::<Msb0>();

let accum = bits
  .as_raw_slice()
  .iter()
  .copied()
  .map(u8::count_ones)
  .sum::<u32>();
assert_eq!(accum, 3);

pub fn as_raw_slice_mut(&mut self) -> &mut [T::Mem][src]

Views the wholly-filled elements of the BitSlice.

This will not include partially-owned edge elements, as they may be aliased by other handles. To gain access to all elements that the BitSlice region covers, use one of the following:

  • .as_aliased_slice produces a shared slice over all elements, marked as aliased to allow for the possibliity of mutation.
  • .domain_mut produces a view describing each component of the region, marking only the contended edges as aliased and the uncontended interior as unaliased.

Parameters

  • &mut self

Returns

A mutable slice of all the wholly-filled elements in the BitSlice backing storage.

Examples

use bitvec::prelude::*;

let mut data = [1u8, 64];
let bits = data.view_bits_mut::<Msb0>();
for elt in bits.as_raw_slice_mut() {
  *elt |= 2;
}
assert_eq!(&[3, 66], bits.as_slice());

pub fn bit_domain(&self) -> BitDomain<'_, O, T>[src]

Splits the slice into the logical components of its memory domain.

This produces a set of read-only subslices, marking as much as possible as affirmatively lacking any write-capable view (T::NoAlias). The unaliased view is able to safely perform unsynchronized reads from memory without causing undefined behavior, as the type system is able to statically prove that no other write-capable views exist.

Parameters

  • &self

Returns

A BitDomain structure representing the logical components of the memory region.

Safety Exception

The following snippet describes a means of constructing a T::NoAlias view into memory that is, in fact, aliased:

use bitvec::prelude::*;
use core::sync::atomic::AtomicU8;
type Bs<T> = BitSlice<LocalBits, T>;

let data = [AtomicU8::new(0), AtomicU8::new(0), AtomicU8::new(0)];
let bits: &Bs<AtomicU8> = data.view_bits::<LocalBits>();
let subslice: &Bs<AtomicU8> = &bits[4 .. 20];

let (_, noalias, _): (_, &Bs<u8>, _) =
  subslice.bit_domain().region().unwrap();

The noalias reference, which has memory type u8, assumes that it can act as an &u8 reference: unsynchronized loads are permitted, as no handle exists which is capable of modifying the middle bit of data. This means that LLVM is permitted to issue loads from memory wherever it wants in the block during which noalias is live, as all loads are equivalent.

Use of the bits or subslice handles, which are still live for the lifetime of noalias, to issue .set_aliased calls into the middle element introduce undefined behavior. bitvec permits safe code to introduce this undefined behavior solely because it requires deliberate opt-in – you must start from atomic data; this cannot occur when data is non-atomic – and use of the shared-mutation facility simultaneously with the unaliasing view.

The .set_aliased method is speculative, and will be marked as unsafe or removed at any suspicion that its presence in the library has any costs.

Examples

This method can be used to accelerate reads from a slice that is marked as aliased.

use bitvec::prelude::*;
type Bs<T> = BitSlice<LocalBits, T>;

let mut data = [0u8; 3];
let bits = data.view_bits_mut::<LocalBits>();
let (a, b): (
  &mut Bs<<u8 as BitStore>::Alias>,
  &mut Bs<<u8 as BitStore>::Alias>,
) = bits.split_at_mut(4);
let (partial, full, _): (
  &Bs<<u8 as BitStore>::Alias>,
  &Bs<<u8 as BitStore>::Mem>,
  _,
) = b.bit_domain().region().unwrap();
read_from(partial); // uses alias-aware reads
read_from(full); // uses ordinary reads

pub fn bit_domain_mut(&mut self) -> BitDomainMut<'_, O, T>[src]

Splits the slice into the logical components of its memory domain.

This produces a set of mutable subslices, marking as much as possible as affirmatively lacking any other view (T::Mem). The bare view is able to safely perform unsynchronized reads from and writes to memory without causing undefined behavior, as the type system is able to statically prove that no other views exist.

Why This Is More Sound Than .bit_domain

The &mut exclusion rule makes it impossible to construct two references over the same memory where one of them is marked &mut. This makes it impossible to hold a live reference to memory separately from any references produced from this method. For the duration of all references produced by this method, all ancestor references used to reach this method call are either suspended or dead, and the compiler will not allow you to use them.

As such, this method cannot introduce undefined behavior where a reference incorrectly believes that the referent memory region is immutable.

pub fn domain(&self) -> Domain<'_, T>

Notable traits for Domain<'a, T>

impl<'a, T> Iterator for Domain<'a, T> where
    T: 'a + BitStore
type Item = T::Mem;
[src]

Splits the slice into immutable references to its underlying memory components.

Unlike .bit_domain and .bit_domain_mut, this does not return smaller BitSlice handles but rather appropriately-marked references to the underlying memory elements.

The aliased references allow mutation of these elements. You are required to not use mutating methods on these references at all. This function is not marked unsafe, but this is a contract you must uphold. Use .domain_mut to modify the underlying elements.

It is not currently possible to forbid mutation through these references. This may change in the future.

Safety Exception

As with .bit_domain, this produces unsynchronized immutable references over the fully-populated interior elements. If this view is constructed from a BitSlice handle over atomic memory, then it will remove the atomic access behavior for the interior elements. This by itself is safe, as long as no contemporaneous atomic writes to that memory can occur. You must not retain and use an atomic reference to the memory region marked as NoAlias for the duration of this view’s existence.

Parameters

  • &self

Returns

A read-only descriptor of the memory elements backing *self.

pub fn domain_mut(&mut self) -> DomainMut<'_, T>[src]

Splits the slice into mutable references to its underlying memory elements.

Like .domain, this returns appropriately-marked references to the underlying memory elements. These references are all writable.

The aliased edge references permit modifying memory beyond their bit marker. You are required to only mutate the region of these edge elements that you currently govern. This function is not marked unsafe, but this is a contract you must uphold.

It is not currently possible to forbid out-of-bounds mutation through these references. This may change in the future.

Parameters

  • &mut self

Returns

A descriptor of the memory elements underneath *self, permitting mutation.

pub unsafe fn split_at_unchecked(&self, mid: usize) -> (&Self, &Self)[src]

Splits a slice at some mid-point, without checking boundary conditions.

This is generally not recommended; use with caution! For a safe alternative, see split_at.

Parameters

  • &self
  • mid: The index at which to split the slice. This must be in the range 0 .. self.len().

Returns

  • .0: &self[.. mid]
  • .1: &self[mid ..]

Safety

This function is not safe. It performs raw pointer arithmetic to construct two new references. If mid is out of bounds, then the first slice will be too large, and the second will be catastrophically incorrect. As both are references to invalid memory, they are undefined to construct, and may not ever be used.

Examples

use bitvec::prelude::*;

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

let (one, two) = unsafe { bits.split_at_unchecked(8) };
assert!(one[7]);
assert!(two[0]);

pub unsafe fn split_at_unchecked_mut(
    &mut self,
    mid: usize
) -> (&mut BitSlice<O, T::Alias>, &mut BitSlice<O, T::Alias>)
[src]

Splits a mutable slice at some mid-point, without checking boundary conditions.

This is generally not recommended; use with caution! For a safe alternative, see split_at_mut.

Parameters

  • &mut self
  • mid: The index at which to split the slice. This must be in the range 0 .. self.len().

Returns

  • .0: &mut self[.. mid]
  • .1: &mut self[mid ..]

Safety

This function is not safe. It performs raw pointer arithmetic to construct two new references. If mid is out of bounds, then the first slice will be too large, and the second will be catastrophically incorrect. As both are references to invalid memory, they are undefined to construct, and may not ever be used.

Examples

use bitvec::prelude::*;

let mut data = 0u16;
let bits = data.view_bits_mut::<Msb0>();

let (one, two) = unsafe { bits.split_at_unchecked_mut(8) };
one.set(7, true);
two.set(0, true);
assert_eq!(data, 0x0180u16);

pub unsafe fn swap_unchecked(&mut self, a: usize, b: usize)[src]

Swaps the bits at two indices without checking boundary conditions.

This is generally not recommended; use with caution! For a safe alternative, see swap.

Parameters

  • &mut self
  • a: One index to swap.
  • b: The other index to swap.

Effects

The bit at index a is written into index b, and the bit at index b is written into a.

Safety

Both a and b must be less than self.len(). Indices greater than the length will cause out-of-bounds memory access, which can lead to memory unsafety and a program crash.

Examples

use bitvec::prelude::*;

let mut data = 8u8;
let bits = data.view_bits_mut::<Msb0>();

unsafe { bits.swap_unchecked(0, 4); }

assert_eq!(data, 128);

pub unsafe fn copy_unchecked(&mut self, from: usize, to: usize)[src]

Copies a bit from one index to another without checking boundary conditions.

Parameters

  • &mut self
  • from: The index whose bit is to be copied
  • to: The index into which the copied bit is written.

Effects

The bit at from is written into to.

Safety

Both from and to must be less than self.len(), in order for self to legally read from and write to them, respectively.

If self had been split from a larger slice, reading from from or writing to to may not necessarily cause a memory-safety violation in the Rust model, due to the aliasing system bitvec employs. However, writing outside the bounds of a slice reference is always a logical error, as it causes changes observable by another reference handle.

Examples

use bitvec::prelude::*;

let mut data = 1u8;
let bits = data.view_bits_mut::<Lsb0>();

unsafe { bits.copy_unchecked(0, 2) };

assert_eq!(data, 5);

pub unsafe fn copy_within_unchecked<R>(&mut self, src: R, dest: usize) where
    R: RangeBounds<usize>, 
[src]

Copies bits from one part of the slice to another part of itself.

src is the range within self to copy from. dest is the starting index of the range within self to copy to, which will have the same length as src. The two ranges may overlap. The ends of the two ranges must be less than or equal to self.len().

Effects

self[src] is copied to self[dest .. dest + src.end() - src.start()].

Panics

This function will panic if either range exceeds the end of the slice, or if the end of src is before the start.

Safety

Both the src range and the target range dest .. dest + src.len() must not exceed the self.len() slice range.

Examples

use bitvec::prelude::*;

let mut data = 0x07u8;
let bits = data.view_bits_mut::<Msb0>();

unsafe { bits.copy_within_unchecked(5 .., 0); }

assert_eq!(data, 0xE7);

pub fn split_at_aliased_mut(&mut self, mid: usize) -> (&mut Self, &mut Self)[src]

Splits a mutable slice at some mid-point.

This method has the same behavior as split_at_mut, except that it does not apply an aliasing marker to the partitioned subslices.

Safety

Because this method is defined only on BitSlices whose T type is alias-safe, the subslices do not need to be additionally marked.

pub unsafe fn split_at_aliased_unchecked_mut(
    &mut self,
    mid: usize
) -> (&mut Self, &mut Self)
[src]

Splits a mutable slice at some mid-point, without checking boundary conditions.

This method has the same behavior as split_at_unchecked_mut, except that it does not apply an aliasing marker to the partitioned subslices.

Safety

See split_at_unchecked_mut for safety requirements.

Because this method is defined only on BitSlices whose T type is alias-safe, the subslices do not need to be additionally marked.

pub const MAX_BITS: usize[src]

pub const MAX_ELTS: usize[src]

Trait Implementations

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

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

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

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

type Output = Self

The resulting type after applying the & operator.

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

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

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

type Output = Self

The resulting type after applying the | operator.

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

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

type Output = Self

The resulting type after applying the ^ operator.

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

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

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

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

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

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

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

type Target = BitSlice<O, T>

The resulting type after dereferencing.

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

impl<'de, O, T> Deserialize<'de> for BitVec<O, T> where
    O: BitOrder,
    T: BitStore,
    T::Mem: Deserialize<'de>, 
[src]

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

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

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

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

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

impl<'a, O, T> From<&'a BitSlice<O, T>> for BitVec<O, T> where
    O: BitOrder,
    T: BitStore
[src]

impl<'a, O, T> From<&'a mut BitSlice<O, T>> for BitVec<O, T> where
    O: BitOrder,
    T: BitStore
[src]

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

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

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

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

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

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

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

The returned type after indexing.

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

impl<O, T> Into<Vec<T>> for BitVec<O, T> where
    O: BitOrder,
    T: BitStore
[src]

impl<O, T> IntoIterator for BitVec<O, T> where
    O: 'static + BitOrder,
    T: 'static + BitStore
[src]

type IntoIter = IntoIter<O, T>

Which kind of iterator are we turning this into?

type Item = bool

The type of the elements being iterated over.

impl<'a, O, T> IntoIterator for &'a BitVec<O, T> where
    O: 'a + BitOrder,
    T: 'a + BitStore
[src]

type IntoIter = <&'a BitSlice<O, T> as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?

type Item = <&'a BitSlice<O, T> as IntoIterator>::Item

The type of the elements being iterated over.

impl<'a, O, T> IntoIterator for &'a mut BitVec<O, T> where
    O: 'a + BitOrder,
    T: 'a + BitStore
[src]

type IntoIter = <&'a mut BitSlice<O, T> as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?

type Item = <&'a mut BitSlice<O, T> as IntoIterator>::Item

The type of the elements being iterated over.

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

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

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_mit_bitslice.

type Output = Self

The resulting type after applying the ! operator.

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

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

impl<O1, O2, T1, T2> PartialEq<BitVec<O2, T2>> for BitSlice<O1, T1> where
    O1: BitOrder,
    O2: BitOrder,
    T1: BitStore,
    T2: BitStore
[src]

impl<O1, O2, T1, T2, '_> PartialEq<BitVec<O2, T2>> for &'_ BitSlice<O1, T1> where
    O1: BitOrder,
    O2: BitOrder,
    T1: BitStore,
    T2: BitStore
[src]

impl<O1, O2, T1, T2, '_> PartialEq<BitVec<O2, T2>> for &'_ mut BitSlice<O1, T1> where
    O1: BitOrder,
    O2: BitOrder,
    T1: BitStore,
    T2: BitStore
[src]

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

impl<O, T> PartialOrd<BitVec<O, T>> for BitSlice<O, T> where
    O: BitOrder,
    T: BitStore
[src]

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

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

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

impl<O, T> Serialize for BitVec<O, T> where
    O: BitOrder,
    T: BitStore,
    T::Mem: Serialize
[src]

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

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

type Error = Vec<T>

The type returned in the event of a conversion error.

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

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

impl<O, T> Write for BitVec<O, T> where
    O: BitOrder,
    T: BitStore,
    BitSlice<O, T::Alias>: BitField
[src]

Mirrors the implementation on Vec<u8> (found here).

The implementation copies bytes from buf into the tail end of self. The performance characteristics of this operation are dependent on the type parameters of the BitVec, and the position of its tail.

Auto Trait Implementations

impl<O, T> RefUnwindSafe for BitVec<O, T> where
    O: RefUnwindSafe,
    T: RefUnwindSafe

impl<O, T> UnwindSafe for BitVec<O, T> where
    O: RefUnwindSafe,
    T: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> FmtForward for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> Pipe for T[src]

impl<T> PipeAsRef for T[src]

impl<T> PipeBorrow for T[src]

impl<T> PipeDeref for T[src]

impl<T> PipeRef for T[src]

impl<T> Tap for T[src]

impl<T, U> TapAsRef<U> for T where
    U: ?Sized
[src]

impl<T, U> TapBorrow<U> for T where
    U: ?Sized
[src]

impl<T> TapDeref for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> TryConv for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.