[][src]Struct bitvec::slice::BitSlice

#[repr(transparent)]
pub struct BitSlice<C = BigEndian, T = u8> where
    C: Cursor,
    T: BitStore
{ /* fields omitted */ }

A compact slice of bits, whose cursor and storage types can be customized.

BitSlice is a specialized slice type, which can only ever be held by reference or specialized owning pointers provided by this crate. The value patterns of its handles are opaque binary structures, which cannot be meaningfully inspected by user code.

BitSlice can only be dynamically allocated by this library. Creation of any other BitSlice collections will result in severely incorrect behavior.

A BitSlice reference can be created through the bitvec! macro, from a BitVec collection, or from most common Rust types (fundamentals, slices of them, and small arrays) using the Bits and BitsMut traits.

BitSlices are a view into a block of memory at bit-level resolution. They are represented by a crate-internal pointer structure that cannot be used with other Rust code except through the provided conversion APIs.

use bitvec::prelude::*;

let bv = bitvec![0, 1, 0, 1];
//  slicing a bitvec
let bslice: &BitSlice = &bv[..];
//  coercing an array to a bitslice
let bslice: &BitSlice = [1u8, 254u8].as_bitslice::<BigEndian>();

Bit slices are either mutable or shared. The shared slice type is &BitSlice<C, T>, while the mutable slice type is &mut BitSlice<C, T>. For example, you can mutate bits in the memory to which a mutable BitSlice points:

use bitvec::prelude::*;

let mut base = [0u8, 0, 0, 0];
{
 let bs: &mut BitSlice = base.as_mut_bitslice::<BigEndian>();
 bs.set(13, true);
 eprintln!("{:?}", bs.as_ref());
 assert!(bs[13]);
}
assert_eq!(base[1], 4);

Type Parameters

  • C: Cursor: An implementor of the Cursor trait. This type is used to convert semantic indices into concrete bit positions in elements, and store or retrieve bit values from the storage type.
  • T: BitStore: An implementor of the BitStore trait: u8, u16, u32, or u64 (64-bit systems only). This is the actual type in memory that the slice will use to store data.

Safety

The &BitSlice reference handle has the same size as standard Rust slice handles, but it is extremely binary incompatible with them. Attempting to treat &BitSlice<_, T> as &[T] in any manner except through the provided APIs is catastrophically unsafe and unsound.

Methods

impl<C, T> BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

pub fn empty<'a>() -> &'a Self[src]

Produces the empty slice. This is equivalent to &[] for Rust slices.

Returns

An empty &BitSlice handle.

Examples

use bitvec::prelude::*;

let bits: &BitSlice = BitSlice::empty();

pub fn empty_mut<'a>() -> &'a mut Self[src]

Produces the empty mutable slice. This is equivalent to &mut [] for Rust slices.

Returns

An empty &mut BitSlice handle.

Examples

use bitvec::prelude::*;

let bits: &mut BitSlice = BitSlice::empty_mut();

pub fn from_element(elt: &T) -> &Self[src]

Produces an immutable BitSlice over a single element.

Parameters

  • elt: A reference to an element over which the BitSlice will be created.

Returns

A BitSlice over the provided element.

Examples

use bitvec::prelude::*;

let elt: u8 = !0;
let bs: &BitSlice = BitSlice::from_element(&elt);
assert!(bs.all());

pub fn from_element_mut(elt: &mut T) -> &mut Self[src]

Produces a mutable BitSlice over a single element.

Parameters

  • elt: A reference to an element over which the BitSlice will be created.

Returns

A BitSlice over the provided element.

Examples

use bitvec::prelude::*;

let mut elt: u8 = !0;
let bs: &mut BitSlice = BitSlice::from_element_mut(&mut elt);
bs.set(0, false);
assert!(!bs.all());

pub fn from_slice(slice: &[T]) -> &Self[src]

Wraps a &[T: BitStore] in a &BitSlice<C: Cursor, T>. The cursor must be specified at the call site. The element type cannot be changed.

Parameters

  • src: The elements over which the new BitSlice will operate.

Returns

A BitSlice representing the original element slice.

Panics

The source slice must not exceed the maximum number of elements that a BitSlice can contain. This value is documented in BitPtr.

Examples

use bitvec::prelude::*;

let src = [1, 2, 3];
let bits = BitSlice::<BigEndian, u8>::from_slice(&src[..]);
assert_eq!(bits.len(), 24);
assert_eq!(bits.as_ref().len(), 3);
assert!(bits[7]);  // src[0] == 0b0000_0001
assert!(bits[14]); // src[1] == 0b0000_0010
assert!(bits[22]); // src[2] == 0b0000_0011
assert!(bits[23]);

pub fn from_slice_mut(slice: &mut [T]) -> &mut Self[src]

Wraps a &mut [T: BitStore] in a &mut BitSlice<C: Cursor, T>. The cursor must be specified by the call site. The element type cannot be changed.

Parameters

  • src: The elements over which the new BitSlice will operate.

Returns

A BitSlice representing the original element slice.

Panics

The source slice must not exceed the maximum number of elements that a BitSlice can contain. This value is documented in BitPtr.

Examples

use bitvec::prelude::*;

let mut src = [1, 2, 3];
let bits = BitSlice::<LittleEndian, u8>::from_slice_mut(&mut src[..]);
//  The first bit is the LSb of the first element.
assert!(bits[0]);
bits.set(0, false);
assert!(!bits[0]);
assert_eq!(bits.as_ref(), &[0, 2, 3]);

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

Returns the number of bits contained in the BitSlice.

Parameters

  • &self

Returns

The number of live bits in the slice domain.

Examples

use bitvec::prelude::*;

let store = 0u8;
let bs = store.as_bitslice::<BigEndian>();
assert_eq!(bs.len(), 8);

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

Tests if the slice is empty.

Parameters

  • &self

Returns

Whether the slice has no live bits.

Examples

use bitvec::prelude::*;

let bs = BitSlice::<BigEndian, u8>::empty();
assert!(bs.is_empty());
let bs = 0u8.as_bitslice::<BigEndian>();
assert!(!bs.is_empty());

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

Gets the first element of the slice, if present.

Parameters

  • &self

Returns

None if the slice is empty, or Some(bit) if it is not.

Examples

use bitvec::prelude::*;

assert!(BitSlice::<BigEndian, u8>::empty().first().is_none());
assert!(128u8.as_bitslice::<BigEndian>().first().unwrap());

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.

Parameters

  • &self

Returns

If the slice is empty, this returns None, otherwise, it returns Some of:

  • the first bit
  • a &BitSlice of all the rest of the bits (this may be empty)

Examples

use bitvec::prelude::*;

assert!(BitSlice::<BigEndian, u8>::empty().split_first().is_none());

let store = 128u8;
let bits = store.as_bitslice::<BigEndian>();
let (h, t) = bits.split_first().unwrap();
assert!(h);
assert!(t.not_any());

let (h, t) = bits[0 .. 1].split_first().unwrap();
assert!(h);
assert!(t.is_empty());

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

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

Parameters

  • &self

Returns

If the slice is empty, this returns None, otherwise, it returns Some of:

  • the first bit
  • a &mut BitSlice of all the rest of the bits (this may be empty)

Examples

use bitvec::prelude::*;

let mut store = 0u8;
let bits = store.as_mut_bitslice::<LittleEndian>();
assert!(!bits[0]);
*bits.at(0) = true;
let (h, t) = bits.split_first_mut().unwrap();
assert!(h);
assert_eq!(t.len(), 7);

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

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

Parameters

  • &self

Returns

If the slice is empty, this returns None, otherwise, it returns Some of:

  • the last bit
  • a &BitSlice of all the rest of the bits (this may be empty)

Examples

use bitvec::prelude::*;

assert!(BitSlice::<BigEndian, u8>::empty().split_last().is_none());

let bits = 1u8.as_bitslice::<BigEndian>();
let (t, h) = bits.split_last().unwrap();
assert!(t);
assert!(h.not_any());

let bits = &bits[7 .. 8];
let (t, h) = bits.split_last().unwrap();
assert!(t);
assert!(h.is_empty());

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

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

Parameters

  • &self

Returns

If the slice is empty, this returns None, otherwise, it returns Some of:

  • the last bit
  • a &BitSlice of all the rest of the bits (this may be empty)

Examples

use bitvec::prelude::*;

let mut store = 0u8;
let bits = store.as_mut_bitslice::<LittleEndian>();
assert!(!bits[7]);
*bits.at(7) = true;
let (h, t) = bits.split_last_mut().unwrap();
assert!(h);
assert_eq!(t.len(), 7);

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

Gets the last element of the slice, or None if it is empty.

Parameters

  • &self

Returns

None if the slice is empty, or Some(bit) if it is not.

Examples

use bitvec::prelude::*;

assert!(BitSlice::<BigEndian, u8>::empty().last().is_none());
assert!(1u8.as_bitslice::<BigEndian>().last().unwrap());

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

Gets the bit value at the given position.

Parameters

  • &self
  • index: The bit index to retrieve.

Returns

The bit at the specified index, if any. If index is beyond the bounds of self, then None is produced.

Examples

use bitvec::prelude::*;

let bits = 8u8.as_bitslice::<BigEndian>();
assert!(bits.get(4).unwrap());
assert!(!bits.get(3).unwrap());
assert!(bits.get(10).is_none());

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

Looks up a bit at an index, without doing bounds checking.

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

Parameters

  • &self
  • index: The bit index to retrieve. This index is not checked against the length of self.

Returns

The bit at the requested index.

Safety

This method is not safe. It performs raw pointer arithmetic to seek from the start of the slice to the requested index, and look up the bit there. It does not inspect the length of self, and it is free to perform out-of-bounds memory 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 src = 1u8;
let bits = &src.as_bitslice::<BigEndian>()[2 .. 4];
assert_eq!(bits.len(), 2);
assert!(unsafe { bits.get_unchecked(5) });

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 domain 0 .. self.len().
  • value: The value to be set, true for 1 and false for 0.

Panics

This method panics if index is outside the slice domain.

Examples

use bitvec::prelude::*;

let mut store = 8u8;
let bits = store.as_mut_bitslice::<BigEndian>();
assert!(!bits[3]);
bits.set(3, true);
assert!(bits[3]);

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

Sets a bit at an index, without doing bounds checking.

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

Parameters

  • &mut self
  • index: The bit index to retrieve. This index is not checked against the length of self.

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 src = 0u8;
{
 let bits = &mut src.as_mut_bitslice::<BigEndian>()[2 .. 4];
 assert_eq!(bits.len(), 2);
 unsafe { bits.set_unchecked(5, true); }
}
assert_eq!(src, 1);

pub fn at(&mut self, index: usize) -> BitGuard<C, T>[src]

Produces a write reference to a single bit in the slice.

The structure returned by this method extends the borrow until it drops, which precludes parallel use.

The split_at_mut method allows splitting the borrows of a slice, and will enable safe parallel use of these write references. The atomic feature guarantees that parallel use does not cause data races when modifying the underlying slice.

Lifetimes

  • 'a Propagates the lifetime of the referent slice to the single-bit reference produced.

Parameters

  • &mut self
  • index: The index of the bit in self selected.

Returns

A write reference to the requested bit. Due to Rust limitations, this is not a native reference type, but is a custom structure that holds the address of the requested bit and its value. The produced structure implements Deref and DerefMut to its cached bit, and commits the cached bit to the parent slice on drop.

Usage

You must use the dereference operator on the .at() expression in order to assign to it. In general, you should prefer immediately using and discarding the returned value, rather than binding it to a name and letting it live for more than one statement.

Examples

use bitvec::prelude::*;

let mut src = 0u8;
let bits = src.as_mut_bitslice::<BigEndian>();

assert!(!bits[0]);
*bits.at(0) = true;
//  note the leading dereference.
assert!(bits[0]);

This example shows multiple usage by using split_at_mut.

use bitvec::prelude::*;

let mut src = 0u8;
let bits = src.as_mut_bitslice::<BigEndian>();

{
 let (mut a, rest) = bits.split_at_mut(2);
 let (mut b, rest) = rest.split_at_mut(3);
 *a.at(0) = true;
 *b.at(0) = true;
 *rest.at(0) = true;
}

assert_eq!(bits.as_slice()[0], 0b1010_0100);
//                               a b   rest

The above example splits the slice into three (the first, the second, and the rest) in order to hold multiple write references into the slice.

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

Retrieves a read pointer to the start of the underlying data slice.

Parameters

  • &self

Returns

A pointer to the first element, partial or not, in the underlying store.

If self is empty, then the null pointer is returned.

Safety

The caller must ensure that the slice outlives the pointer this function returns, or else it will dangle and point to garbage.

Modifying the container referenced by this slice may cause its buffer to reallocate, which would also make any pointers to it invalid.

Examples

use bitvec::prelude::*;

let src = [0u8; 4];
let bits = src.as_bitslice::<BigEndian>();
assert_eq!(src.as_ptr(), bits.as_ptr());

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

Retrieves a write pointer to the start of the underlying data slice.

Parameters

  • &mut self

Returns

A pointer to the first element, partial or not, in the underlying store.

If self is empty, then the null pointer is returned.

Safety

The caller must ensure that the slice outlives the pointer this function returns, or else it will dangle and point to garbage.

Modifying the container referenced by this slice may cause its buffer to reallocate, which would also make any pointers to it invalid.

Examples

use bitvec::prelude::*;

let mut src = [0u8; 4];
let src_ptr = src.as_mut_ptr();
let bits = src.as_mut_bitslice::<BigEndian>();
assert_eq!(src_ptr, bits.as_mut_ptr());

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

Swaps two bits in the slice.

Parameters

  • &mut self
  • a: The first index to be swapped.
  • b: The second index to be swapped.

Panics

Panics if either a or b are out of bounds.

Examples

use bitvec::prelude::*;

let mut store = 32u8;
let bits = store.as_mut_bitslice::<BigEndian>();
assert!(!bits[0]);
assert!(bits[2]);
bits.swap(0, 2);
assert!(bits[0]);
assert!(!bits[2]);

pub fn reverse(&mut self)[src]

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

Parameters

  • &mut self

Examples

use bitvec::prelude::*;

let mut src = 0b1010_1010u8;
{
  let bits = src.as_mut_bitslice::<BigEndian>();
  bits[1 .. 7].reverse();
}
eprintln!("{:b}", src);
assert_eq!(src, 0b1101_0100);

Important traits for Iter<'a, C, T>
pub fn iter(&self) -> Iter<C, T>[src]

Provides read-only iteration across the slice domain.

The iterator returned from this method implements ExactSizeIterator and DoubleEndedIterator just as the consuming .into_iter() method’s iterator does.

Parameters

  • &self

Returns

An iterator over all bits in the slice domain, in C and T ordering.

Examples

use bitvec::prelude::*;

let src = 64u8;
let bits = src.as_bitslice::<BigEndian>();
let mut iter = bits[.. 2].iter();
assert!(!iter.next().unwrap());
assert!(iter.next().unwrap());
assert!(iter.next().is_none());

Important traits for Windows<'a, C, T>
pub fn windows(&self, size: usize) -> Windows<C, T>[src]

Produces a sliding iterator over consecutive windows in the slice. Each windows has the width size. The windows overlap. If the slice is shorter than size, the produced iterator is empty.

Parameters

  • &self
  • size: The width of each window.

Returns

An iterator which yields sliding views into the slice.

Panics

This function panics if the size is zero.

Examples

use bitvec::prelude::*;

let src = 0b0100_1011u8;
let bits = src.as_bitslice::<BigEndian>();
let mut windows = bits.windows(4);
assert_eq!(windows.next(), Some(&bits[0 .. 4]));
assert_eq!(windows.next(), Some(&bits[1 .. 5]));
assert_eq!(windows.next(), Some(&bits[2 .. 6]));
assert_eq!(windows.next(), Some(&bits[3 .. 7]));
assert_eq!(windows.next(), Some(&bits[4 .. 8]));
assert!(windows.next().is_none());

Important traits for Chunks<'a, C, T>
pub fn chunks(&self, size: usize) -> Chunks<C, T>[src]

Produces a galloping iterator over consecutive chunks in the slice. Each chunk, except possibly the last, has the width size. The chunks do not overlap. If the slice is shorter than size, the produced iterator produces only one chunk.

Parameters

  • &self
  • size: The width of each chunk.

Returns

An iterator which yields consecutive chunks of the slice.

Panics

This function panics if the size is zero.

Examples

use bitvec::prelude::*;

let src = 0b0100_1011u8;
let bits = src.as_bitslice::<BigEndian>();
let mut chunks = bits.chunks(3);
assert_eq!(chunks.next(), Some(&bits[0 .. 3]));
assert_eq!(chunks.next(), Some(&bits[3 .. 6]));
assert_eq!(chunks.next(), Some(&bits[6 .. 8]));
assert!(chunks.next().is_none());

Important traits for ChunksMut<'a, C, T>
pub fn chunks_mut(&mut self, size: usize) -> ChunksMut<C, T>[src]

Produces a galloping iterator over consecutive chunks in the slice. Each chunk, except possibly the last, has the width size. The chunks do not overlap. If the slice is shorter than size, the produced iterator produces only one chunk.

Parameters

  • &mut self
  • size: The width of each chunk.

Returns

An iterator which yields consecutive mutable chunks of the slice.

Panics

This function panics if the size is zero.

Examples

use bitvec::prelude::*;

let mut src = 0b0100_1011u8;
{
 let bits = src.as_mut_bitslice::<BigEndian>();
 let mut chunks = bits.chunks_mut(3);
 chunks.next().unwrap().set(2, true);
 chunks.next().unwrap().set(2, true);
 chunks.next().unwrap().set(1, false);
}
assert_eq!(src, 0b0110_1110);

Important traits for ChunksExact<'a, C, T>
pub fn chunks_exact(&self, size: usize) -> ChunksExact<C, T>[src]

Produces a galloping iterator over consecutive chunks in the slice. Each chunk has the width size. If size does not evenly divide the slice, then the remainder is not part of the iteration, and can be accessed separately with the .remainder() method.

Parameters

  • &self
  • size: The width of each chunk.

Returns

An iterator which yields consecutive chunks of the slice.

Panics

This function panics if size is zero.

Examples

use bitvec::prelude::*;

let src = 0b0100_1011u8;
let bits = src.as_bitslice::<BigEndian>();
let mut chunks_exact = bits.chunks_exact(3);
assert_eq!(chunks_exact.next(), Some(&bits[0 .. 3]));
assert_eq!(chunks_exact.next(), Some(&bits[3 .. 6]));
assert!(chunks_exact.next().is_none());
assert_eq!(chunks_exact.remainder(), &bits[6 .. 8]);

Important traits for ChunksExactMut<'a, C, T>
pub fn chunks_exact_mut(&mut self, size: usize) -> ChunksExactMut<C, T>[src]

Produces a galloping iterator over consecutive chunks in the slice. Each chunk has the width size. If size does not evenly divide the slice, then the remainder is not part of the iteration, and can be accessed separately with the .remainder() method.

Parameters

  • &mut self
  • size: The width of each chunk.

Returns

An iterator which yields consecutive mutable chunks of the slice.

Panics

This function panics if size is zero.

Examples

use bitvec::prelude::*;

let mut src = 0b0100_1011u8;
{
 let bits = src.as_mut_bitslice::<BigEndian>();
 let mut chunks_exact = bits.chunks_exact_mut(3);
 chunks_exact.next().unwrap().set(2, true);
 chunks_exact.next().unwrap().set(2, true);
 assert!(chunks_exact.next().is_none());
}
assert_eq!(src, 0b0110_1111);

Important traits for RChunks<'a, C, T>
pub fn rchunks(&self, size: usize) -> RChunks<C, T>[src]

Produces a galloping iterator over consecutive chunks in the slice, from the back to the front. Each chunk, except possibly the front, has the width size. The chunks do not overlap. If the slice is shorter than size, then the iterator produces one item.

Parameters

  • &self
  • size: The width of each chunk.

Returns

An iterator which yields consecutive chunks of the slice, from the back to the front.

Panics

This function panics if size is zero.

Examples

use bitvec::prelude::*;

let src = 0b0100_1011u8;
let bits = src.as_bitslice::<BigEndian>();
let mut rchunks = bits.rchunks(3);
assert_eq!(rchunks.next(), Some(&bits[5 .. 8]));
assert_eq!(rchunks.next(), Some(&bits[2 .. 5]));
assert_eq!(rchunks.next(), Some(&bits[0 .. 2]));
assert!(rchunks.next().is_none());

Important traits for RChunksMut<'a, C, T>
pub fn rchunks_mut(&mut self, size: usize) -> RChunksMut<C, T>[src]

Produces a galloping iterator over consecutive chunks in the slice, from the back to the front. Each chunk, except possibly the front, has the width size. The chunks do not overlap. If the slice is shorter than size, then the iterator produces one item.

Parameters

  • &mut self
  • size: The width of each chunk.

Returns

An iterator which yields consecutive mutable chunks of the slice, from the back to the front.

Panics

This function panics if size is zero.

Examples

use bitvec::prelude::*;

let mut src = 0b0100_1011u8;
{
 let bits = src.as_mut_bitslice::<BigEndian>();
 let mut rchunks = bits.rchunks_mut(3);
 rchunks.next().unwrap().set(0, true);
 rchunks.next().unwrap().set(2, false);
 rchunks.next().unwrap().set(1, false);
 assert!(rchunks.next().is_none());
}
assert_eq!(src, 0b0000_0111);

Important traits for RChunksExact<'a, C, T>
pub fn rchunks_exact(&self, size: usize) -> RChunksExact<C, T>[src]

Produces a galloping iterator over consecutive chunks in the slice, from the back to the front. Each chunk has the width size. If size does not evenly divide the slice, then the remainder is not part of the iteration, and can be accessed separately with the .remainder() method.

Parameters

  • &self
  • size: The width of each chunk.

Returns

An iterator which yields consecutive chunks of the slice, from the back to the front.

Panics

This function panics if size is zero.

Examples

use bitvec::prelude::*;

let store: &[u8] = &[0b0100_1011];
let bits: &BitSlice = store.into();
let mut rchunks_exact = bits.rchunks_exact(3);
assert_eq!(rchunks_exact.next(), Some(&bits[5 .. 8]));
assert_eq!(rchunks_exact.next(), Some(&bits[2 .. 5]));
assert!(rchunks_exact.next().is_none());
assert_eq!(rchunks_exact.remainder(), &bits[0 .. 2]);

Important traits for RChunksExactMut<'a, C, T>
pub fn rchunks_exact_mut(&mut self, size: usize) -> RChunksExactMut<C, T>[src]

Produces a galloping iterator over consecutive chunks in the slice, from the back to the front. Each chunk has the width size. If size does not evenly divide the slice, then the remainder is not part of the iteration, and can be accessed separately with the .remainder() method.

Parameters

  • &mut self
  • size: The width of each chunk.

Returns

An iterator which yields consecutive mutable chunks of the slice, from the back to the front.

Panics

This function panics if size is zero.

Examples

use bitvec::prelude::*;

let mut src = 0b0100_1011u8;
{
 let bits = src.as_mut_bitslice::<BigEndian>();
 let mut rchunks_exact = bits.rchunks_exact_mut(3);
 rchunks_exact.next().unwrap().set(0, true);
 rchunks_exact.next().unwrap().set(2, false);
 assert!(rchunks_exact.next().is_none());
}
assert_eq!(src, 0b0100_0111);

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

Parameters

  • &self
  • mid: The index at which to split

Returns

  • The bits up to but not including mid.
  • The bits from mid onwards.

Panics

Panics if mid > self.len().

Examples

use bitvec::prelude::*;

let bits = 15u8.as_bitslice::<BigEndian>();

let (l, r) = bits.split_at(0);
assert!(l.is_empty());
assert_eq!(r, bits);

let (l, r) = bits.split_at(4);
assert_eq!(l, &bits[0 .. 4]);
assert_eq!(r, &bits[4 .. 8]);

let (l, r) = bits.split_at(8);
assert_eq!(l, bits);
assert!(r.is_empty());

pub fn split_at_mut(&mut self, mid: usize) -> (&mut Self, &mut 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).

Parameters

  • &mut self
  • mid: The index at which to split

Returns

  • The bits up to but not including mid.
  • The bits from mid onwards.

Panics

Panics if mid > self.len().

pub fn starts_with<D, U>(&self, prefix: &BitSlice<D, U>) -> bool where
    D: Cursor,
    U: BitStore
[src]

Tests if the slice begins with the given prefix.

Parameters

  • &self
  • prefix: Any BitSlice against which self is tested. This is not required to have the same cursor or storage types as self.

Returns

Whether self begins with prefix. This is true only if self is at least as long as prefix and their bits are semantically equal.

Examples

use bitvec::prelude::*;

let bits = 0xA6u8.as_bitslice::<BigEndian>();
assert!(bits.starts_with(&bits[.. 3]));
assert!(!bits.starts_with(&bits[3 ..]));

pub fn ends_with<D, U>(&self, suffix: &BitSlice<D, U>) -> bool where
    D: Cursor,
    U: BitStore
[src]

Tests if the slice ends with the given suffix.

Parameters

  • &self
  • suffix: Any BitSlice against which self is tested. This is not required to have the same cursor or storage types as self.

Returns

Whether self ends with suffix. This is true only if self is at least as long as suffix and their bits are semantically equal.

Examples

use bitvec::prelude::*;

let bits = 0xA6u8.as_bitslice::<BigEndian>();
assert!(bits.ends_with(&bits[5 ..]));
assert!(!bits.ends_with(&bits[.. 5]));

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

Rotates the slice, in place, to the left.

After calling this method, the bits from [.. by] will be at the back of the slice, and the bits from [by ..] will be at the front. This operates fully in-place.

In-place rotation of bits requires this method to take O(k × n) time. It is impossible to use machine intrinsics to perform galloping rotation on bits.

Parameters

  • &mut self
  • by: The number of bits by which to rotate left. This must be in the range 0 ..= self.len(). If it is 0 or self.len(), then this method is a no-op.

Examples

use bitvec::prelude::*;

let mut src = 0xF0u8;
let bits = src.as_mut_bitslice::<BigEndian>();
bits.rotate_left(2);
assert_eq!(bits.as_ref()[0], 0xC3);

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

Rotates the slice, in place, to the right.

After calling this method, the bits from [self.len() - by ..] will be at the front of the slice, and the bits from [.. self.len() - by] will be at the back. This operates fully in-place.

In-place rotation of bits requires this method to take O(k × n) time. It is impossible to use machine intrinsics to perform galloping rotation on bits.

Parameters

  • &mut self
  • by: The number of bits by which to rotate right. This must be in the range 0 ..= self.len(). If it is 0 or self.len, then this method is a no-op.

Examples

use bitvec::prelude::*;

let mut src = 0xF0u8;
let bits = src.as_mut_bitslice::<BigEndian>();
bits.rotate_right(2);
assert_eq!(bits.as_ref()[0], 0x3C);

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.as_bitslice::<BigEndian>();
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.as_bitslice::<BigEndian>();
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.as_bitslice::<BigEndian>();
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.as_bitslice::<BigEndian>();
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 bits = 0b111_000_10u8.as_bitslice::<BigEndian>();
assert!(!bits[0 .. 3].some());
assert!(!bits[3 .. 6].some());
assert!(bits[6 ..].some());

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

Counts how many bits are set high.

Parameters

  • &self

Returns

The number of high bits in the slice domain.

Examples

use bitvec::prelude::*;

let bits = [0xFDu8, 0x25].as_bitslice::<BigEndian>();
assert_eq!(bits.count_ones(), 10);

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

Counts how many bits are set low.

Parameters

  • &self

Returns

The number of low bits in the slice domain.

Examples

use bitvec::prelude::*;

let bits = [0xFDu8, 0x25].as_bitslice::<BigEndian>();
assert_eq!(bits.count_zeros(), 6);

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

Set 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.as_mut_bitslice::<BigEndian>();
bits[2 .. 6].set_all(true);
assert_eq!(bits.as_ref(), &[0b0011_1100]);
bits[3 .. 5].set_all(false);
assert_eq!(bits.as_ref(), &[0b0010_0100]);
bits[.. 1].set_all(true);
assert_eq!(bits.as_ref(), &[0b1010_0100]);

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

Provides mutable traversal of the collection.

It is impossible to implement IndexMut on BitSlice, because bits do not have addresses, so there can be no &mut u1. This method allows the client to receive an enumerated bit, and provide a new bit to set at each index.

Parameters

  • &mut self
  • func: A function which receives a (usize, bool) pair of index and value, and returns a bool. It receives the bit at each position, and the return value is written back at that position.

Examples

use bitvec::prelude::*;

let mut src = 0u8;
{
 let bits = src.as_mut_bitslice::<BigEndian>();
 bits.for_each(|idx, _bit| idx % 3 == 0);
}
assert_eq!(src, 0b1001_0010);

pub fn add_assign_reverse<I>(&mut self, addend: I) -> bool where
    I: IntoIterator<Item = bool>, 
[src]

Performs “reverse” addition (left to right instead of right to left).

This addition interprets the slice, and the other addend, as having its least significant bits first in the order and its most significant bits last. This is most likely to be numerically useful under a LittleEndian Cursor type.

Parameters

  • &mut self: The addition uses self as one addend, and writes the sum back into self.
  • addend: impl IntoIterator<Item=bool>: A stream of bits. When this is another BitSlice, iteration proceeds from left to right.

Return

The final carry bit is returned

Effects

Starting from index 0 and proceeding upwards until either self or addend expires, the carry-propagated addition of self[i] and addend[i] is written to self[i].

  101111
+ 0010__ (the two missing bits are logically zero)
--------
  100000 1 (the carry-out is returned)

Examples

use bitvec::prelude::*;

let mut a = 0b0000_1010u8;
let     b = 0b0000_1100u8;
//      s =      1 0110
let ab = &mut a.as_mut_bitslice::<LittleEndian>()[.. 4];
let bb = &    b.as_bitslice::<LittleEndian>()[.. 4];
let c = ab.add_assign_reverse(bb);
assert!(c);
assert_eq!(ab.as_slice()[0], 0b0000_0110u8);

Performance Notes

When using LittleEndian Cursor types, this can be accelerated by delegating the addition to the underlying types. This is a software implementation of the ripple-carry adder, which has O(n) runtime in the number of bits. The CPU is much faster, as it has access to element-wise or vectorized addition operations.

If your use case sincerely needs binary-integer arithmetic operations on bit sets

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

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

Parameters

  • &self

Returns

A slice of all the elements that the BitSlice uses for storage.

Examples

use bitvec::prelude::*;

let src = [1u8, 66];
let bits = src.as_bitslice::<BigEndian>();

let accum = bits.as_slice()
  .iter()
  .map(|elt| elt.count_ones())
  .sum::<usize>();
assert_eq!(accum, 3);

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

Accesses the underlying store.

Examples

use bitvec::prelude::*;

let mut src = [1u8, 64];
let bits = src.as_mut_bitslice::<BigEndian>();
for elt in bits.as_mut_slice() {
  *elt |= 2;
}
assert_eq!(&[3, 66], bits.as_slice());

pub fn change_cursor<D>(&self) -> &BitSlice<D, T> where
    D: Cursor
[src]

Changes the cursor type of the slice handle.

Parameters

  • &self

Returns

An equivalent slice handle with a new cursor type.

Type Parameters

  • D: Cursor The new cursor type to use for the handle.

Examples

use bitvec::prelude::*;

let src = 2u8;
let bits = src.as_bitslice::<BigEndian>();
assert!(bits[6]);
let bits = bits.change_cursor::<LittleEndian>();
assert!(bits[1]);

pub fn change_cursor_mut<D>(&mut self) -> &mut BitSlice<D, T> where
    D: Cursor
[src]

Changes the cursor type of the slice handle.

Parameters

  • &mut self

Returns

An equivalent slice handle with a new cursor type.

Type Parameters

  • D: Cursor The new cursor type to use for the handle.

Examples

use bitvec::prelude::*;

let mut src = 0u8;
*src.as_mut_bitslice::<BigEndian>().at(1) = true;
assert_eq!(src, 64);
src.as_mut_bitslice::<BigEndian>()
   .change_cursor_mut::<LittleEndian>()
   .set(1, true);
assert_eq!(src, 66);

pub fn bitptr(&self) -> BitPtr<T>[src]

Accesses the underlying pointer structure.

Parameters

  • &self

Returns

The BitPtr structure of the slice handle.

Trait Implementations

impl<C, T> ToOwned for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

Creates an owned BitVec<C, T> from a borrowed BitSlice<C, T>.

type Owned = BitVec<C, T>

The resulting type after obtaining ownership.

fn to_owned(&self) -> Self::Owned[src]

Clones a borrowed BitSlice into an owned BitVec.

Examples

use bitvec::prelude::*;

let store = [0u8, 2];
let src = store.as_bitslice::<LittleEndian>();
let dst = src.to_owned();
assert_eq!(src, dst);

fn clone_into(&self, target: &mut Self::Owned)[src]

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

recently added

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

impl<C, T> Sync for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

BitSlice is safe to share between multiple threads.

impl<C, T> Eq for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<C, T> Ord for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

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

Restrict a value to a certain interval. Read more

impl<C, T> Send for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

BitSlice is safe to move across thread boundaries.

impl<C> AsMut<BitSlice<C, u8>> for u8 where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 0] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 1] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 2] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 3] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 4] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 5] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 6] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 7] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 8] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 9] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 10] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 11] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 12] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 13] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 14] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 15] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 16] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 17] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 18] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 19] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 20] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 21] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 22] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 23] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 24] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 25] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 26] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 27] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 28] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 29] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 30] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 31] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u8>> for [u8; 32] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for u16 where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 0] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 1] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 2] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 3] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 4] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 5] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 6] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 7] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 8] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 9] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 10] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 11] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 12] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 13] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 14] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 15] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 16] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 17] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 18] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 19] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 20] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 21] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 22] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 23] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 24] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 25] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 26] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 27] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 28] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 29] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 30] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 31] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u16>> for [u16; 32] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for u32 where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 0] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 1] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 2] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 3] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 4] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 5] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 6] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 7] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 8] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 9] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 10] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 11] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 12] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 13] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 14] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 15] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 16] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 17] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 18] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 19] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 20] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 21] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 22] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 23] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 24] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 25] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 26] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 27] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 28] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 29] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 30] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 31] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u32>> for [u32; 32] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for u64 where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 0] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 1] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 2] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 3] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 4] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 5] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 6] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 7] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 8] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 9] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 10] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 11] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 12] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 13] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 14] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 15] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 16] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 17] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 18] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 19] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 20] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 21] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 22] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 23] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 24] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 25] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 26] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 27] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 28] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 29] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 30] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 31] where
    C: Cursor
[src]

impl<C> AsMut<BitSlice<C, u64>> for [u64; 32] where
    C: Cursor
[src]

impl<C, T> AsMut<[T]> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

Provides write access to all elements in the underlying storage, including the partial head and tail elements if present.

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

Accesses the underlying store.

Parameters

  • &mut self

Returns

A mutable slice of all storage elements.

Examples

use bitvec::prelude::*;

let mut src = [0u8, 128];
let bits = &mut src.as_mut_bitslice::<BigEndian>()[1 .. 9];

for elt in bits.as_mut() {
  *elt += 2;
}

assert_eq!(&[2, 130], bits.as_ref());

impl<C, T> AsMut<BitSlice<C, T>> for BitBox<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<C, T> AsMut<BitSlice<C, T>> for BitVec<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<A, B, C, D> PartialEq<BitSlice<C, D>> for BitSlice<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

Tests if two BitSlices are semantically — not bitwise — equal.

It is valid to compare two slices of different cursor or element types.

The equality condition requires that they have the same number of total bits and that each pair of bits in semantic order are identical.

fn eq(&self, rhs: &BitSlice<C, D>) -> bool[src]

Performas a comparison by ==.

Parameters

  • &self
  • rhs: Another BitSlice against which to compare. This slice can have different cursor or storage types.

Returns

If the two slices are equal, by comparing the lengths and bit values at each semantic index.

Examples

use bitvec::prelude::*;

let lsrc = [8u8, 16, 32, 0];
let rsrc = [0x10_08_04_00u32];
let lbits = lsrc.as_bitslice::<LittleEndian>();
let rbits = rsrc.as_bitslice::<BigEndian>();

assert_eq!(lbits, rbits);

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<A, B, C, D, '_> PartialEq<BitSlice<C, D>> for &'_ BitSlice<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<A, B, C, D> PartialEq<BitVec<C, D>> for BitSlice<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

Allow comparison against the allocated form.

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<A, B, C, D, '_> PartialEq<BitVec<C, D>> for &'_ BitSlice<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<A, B, C, D> PartialEq<BitSlice<C, D>> for BitBox<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<A, B, C, D> PartialEq<BitBox<C, D>> for BitSlice<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<A, B, C, D> PartialEq<BitSlice<C, D>> for BitVec<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<A, B, C, D, '_> PartialEq<&'_ BitSlice<C, D>> for BitVec<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<A, B, C, D> PartialOrd<BitSlice<C, D>> for BitSlice<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

Compares two BitSlices by semantic — not bitwise — ordering.

The comparison sorts by testing each index for one slice to have a set bit where the other has an unset bit. If the slices are different, the slice with the set bit sorts greater than the slice with the unset bit.

If one of the slices is exhausted before they differ, the longer slice is greater.

fn partial_cmp(&self, rhs: &BitSlice<C, D>) -> Option<Ordering>[src]

Performs a comparison by < or >.

Parameters

  • &self
  • rhs: Another BitSlice against which to compare. This slice can have different cursor or storage types.

Returns

The relative ordering of self against rhs. self is greater if it has a true bit at an index where rhs has a false; self is lesser if it has a false bit at an index where rhs has a true; if the two slices do not disagree then they are compared by length.

Examples

use bitvec::prelude::*;

let src = 0x45u8;
let bits = src.as_bitslice::<BigEndian>();
let a = &bits[0 .. 3]; // 010
let b = &bits[0 .. 4]; // 0100
let c = &bits[0 .. 5]; // 01000
let d = &bits[4 .. 8]; // 0101

assert!(a < b);
assert!(b < c);
assert!(c < d);

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<A, B, C, D, '_> PartialOrd<BitSlice<C, D>> for &'_ BitSlice<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<A, B, C, D> PartialOrd<BitVec<C, D>> for BitSlice<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<A, B, C, D, '_> PartialOrd<BitVec<C, D>> for &'_ BitSlice<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<A, B, C, D> PartialOrd<BitSlice<C, D>> for BitBox<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<A, B, C, D> PartialOrd<BitBox<C, D>> for BitSlice<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<A, B, C, D> PartialOrd<BitSlice<C, D>> for BitVec<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<A, B, C, D, '_> PartialOrd<&'_ BitSlice<C, D>> for BitVec<A, B> where
    A: Cursor,
    B: BitStore,
    C: Cursor,
    D: BitStore
[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<C> AsRef<BitSlice<C, u8>> for u8 where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 0] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 1] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 2] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 3] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 4] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 5] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 6] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 7] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 8] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 9] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 10] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 11] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 12] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 13] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 14] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 15] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 16] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 17] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 18] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 19] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 20] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 21] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 22] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 23] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 24] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 25] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 26] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 27] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 28] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 29] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 30] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 31] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u8>> for [u8; 32] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for u16 where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 0] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 1] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 2] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 3] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 4] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 5] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 6] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 7] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 8] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 9] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 10] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 11] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 12] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 13] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 14] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 15] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 16] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 17] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 18] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 19] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 20] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 21] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 22] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 23] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 24] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 25] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 26] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 27] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 28] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 29] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 30] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 31] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u16>> for [u16; 32] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for u32 where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 0] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 1] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 2] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 3] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 4] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 5] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 6] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 7] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 8] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 9] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 10] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 11] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 12] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 13] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 14] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 15] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 16] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 17] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 18] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 19] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 20] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 21] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 22] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 23] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 24] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 25] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 26] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 27] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 28] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 29] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 30] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 31] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u32>> for [u32; 32] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for u64 where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 0] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 1] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 2] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 3] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 4] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 5] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 6] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 7] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 8] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 9] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 10] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 11] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 12] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 13] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 14] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 15] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 16] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 17] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 18] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 19] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 20] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 21] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 22] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 23] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 24] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 25] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 26] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 27] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 28] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 29] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 30] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 31] where
    C: Cursor
[src]

impl<C> AsRef<BitSlice<C, u64>> for [u64; 32] where
    C: Cursor
[src]

impl<C, T> AsRef<[T]> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

Provides read access to all elements in the underlying storage, including the partial head and tail elements if present.

fn as_ref(&self) -> &[T][src]

Accesses the underlying store.

Parameters

  • &self

Returns

An immutable slice of all storage elements.

Examples

use bitvec::prelude::*;

let src = [0u8, 128];
let bits = &src.as_bitslice::<BigEndian>()[1 .. 9];
assert_eq!(&[0, 128], bits.as_ref());

impl<C, T> AsRef<BitSlice<C, T>> for BitBox<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<C, T> AsRef<BitSlice<C, T>> for BitVec<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<'a, C, T> From<&'a T> for &'a BitSlice<C, T> where
    C: Cursor,
    T: 'a + BitStore
[src]

impl<'a, C, T> From<&'a [T]> for &'a BitSlice<C, T> where
    C: Cursor,
    T: 'a + BitStore
[src]

impl<'a, C, T> From<&'a mut T> for &'a mut BitSlice<C, T> where
    C: Cursor,
    T: 'a + BitStore
[src]

impl<'a, C, T> From<&'a mut [T]> for &'a mut BitSlice<C, T> where
    C: Cursor,
    T: 'a + BitStore
[src]

impl<C, T, '_> From<&'_ BitSlice<C, T>> for BitBox<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<C, T, '_> From<&'_ BitSlice<C, T>> for BitVec<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<'a, C, T> Default for &'a BitSlice<C, T> where
    C: Cursor,
    T: 'a + BitStore
[src]

impl<'a, C, T> Default for &'a mut BitSlice<C, T> where
    C: Cursor,
    T: 'a + BitStore
[src]

impl<'a, C, T> IntoIterator for &'a BitSlice<C, T> where
    C: Cursor,
    T: 'a + BitStore
[src]

Produces a read-only iterator over all the bits in the BitSlice.

This iterator follows the ordering in the BitSlice type, and implements ExactSizeIterator as BitSlice has a known, fixed, length, and DoubleEndedIterator as it has known ends.

type Item = bool

The type of the elements being iterated over.

type IntoIter = Iter<'a, C, T>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Iterates over the slice.

Parameters

  • self

Returns

An iterator over the slice domain.

Examples

use bitvec::prelude::*;

let bits = 0b1010_1100u8.as_bitslice::<BigEndian>();
let mut count = 0;
for bit in bits {
  if bit { count += 1; }
}
assert_eq!(count, 4);

impl<C, T> Debug for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

Prints the BitSlice for debugging.

The output is of the form BitSlice<C, T> [ELT, *] where <C, T> is the cursor and element type, with square brackets on each end of the bits and all the elements of the array printed in binary. The printout is always in semantic order, and may not reflect the underlying buffer. To see the underlying buffer, use .as_ref().

The alternate character {:#?} prints each element on its own line, rather than having all elements on the same line.

fn fmt(&self, f: &mut Formatter) -> Result[src]

Renders the BitSlice type header and contents for debug.

Examples

use bitvec::prelude::*;

let src = [0b0101_0000_1111_0101u16, 0b00000000_0000_0010];
let bits = &src.as_bitslice::<LittleEndian>()[.. 18];
assert_eq!(
    "BitSlice<LittleEndian, u16> [1010111100001010, 01]",
    &format!("{:?}", bits),
);

impl<C, T> Display for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

Prints the BitSlice for displaying.

This prints each element in turn, formatted in binary in semantic order (so the first bit seen is printed first and the last bit seen is printed last). Each element of storage is separated by a space for ease of reading.

The alternate character {:#} prints each element on its own line.

To see the in-memory representation, use .as_ref() to get access to the raw elements and print that slice instead.

fn fmt(&self, f: &mut Formatter) -> Result[src]

Renders the BitSlice contents for display.

Parameters

  • &self
  • f: The formatter into which self is written.

Returns

The result of the formatting operation.

Examples

use bitvec::prelude::*;

let src = [0b01001011u8, 0b0100_0000];
let bits = &src.as_bitslice::<BigEndian>()[.. 10];
assert_eq!("[01001011, 01]", &format!("{}", bits));

impl<'a, C, T> Neg for &'a mut BitSlice<C, T> where
    C: Cursor,
    T: 'a + BitStore
[src]

Performs fixed-width 2’s-complement negation of a BitSlice.

Unlike the ! operator (Not trait), the unary - operator treats the BitSlice as if it represents a signed 2’s-complement integer of fixed width. The negation of a number in 2’s complement is defined as its inversion (using !) plus one, and on fixed-width numbers has the following discontinuities:

  • A slice whose bits are all zero is considered to represent the number zero which negates as itself.
  • A slice whose bits are all one is considered to represent the most negative number, which has no correpsonding positive number, and thus negates as zero.

This behavior was chosen so that all possible values would have some output, and so that repeated application converges at idempotence. The most negative input can never be reached by negation, but --MOST_NEG converges at the least unreasonable fallback value, 0.

Because BitSlice cannot move, the negation is performed in place.

type Output = Self

The resulting type after applying the - operator.

fn neg(self) -> Self::Output[src]

Perform 2’s-complement fixed-width negation.

Negation is accomplished by inverting the bits and adding one. This has one edge case: 1000…, the most negative number for its width, will negate to zero instead of itself. It thas no corresponding positive number to which it can negate.

Parameters

  • self

Examples

The contortions shown here are a result of this operator applying to a mutable reference, and this example balancing access to the original BitVec for comparison with aquiring a mutable borrow as a slice to ensure that the BitSlice implementation is used, not the BitVec.

Negate an arbitrary positive number (first bit unset).

use bitvec::prelude::*;

let mut src = 0b0110_1010u8;
let bits = src.as_mut_bitslice::<BigEndian>();
eprintln!("{:?}", bits.split_at(4));
let num = &mut bits[.. 4];
-num;
eprintln!("{:?}", bits.split_at(4));
assert_eq!(&bits[.. 4], &bits[4 ..]);

Negate an arbitrary negative number. This example will use the above result to demonstrate round-trip correctness.

use bitvec::prelude::*;

let mut src = 0b1010_0110u8;
let bits = src.as_mut_bitslice::<BigEndian>();
let num = &mut bits[.. 4];
-num;
assert_eq!(&bits[.. 4], &bits[4 ..]);

Negate the most negative number, which will become zero, and show convergence at zero.

use bitvec::prelude::*;

let mut src = 128u8;
let bits = src.as_mut_bitslice::<BigEndian>();
let num = &mut bits[..];
-num;
assert!(bits.not_any());
let num = &mut bits[..];
-num;
assert!(bits.not_any());

impl<C, T, I> AddAssign<I> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore,
    I: IntoIterator<Item = bool>,
    I::IntoIter: DoubleEndedIterator
[src]

Performs unsigned addition in place on a BitSlice.

If the addend bitstream is shorter than self, the addend is zero-extended at the left (so that its final bit matches with self’s final bit). If the addend is longer, the excess front length is unused.

Addition proceeds from the right ends of each slice towards the left. Because this trait is forbidden from returning anything, the final carry-out bit is discarded.

Note that, unlike BitVec, there is no subtraction implementation until I find a subtraction algorithm that does not require modifying the subtrahend.

Subtraction can be implemented by negating the intended subtrahend yourself and then using addition, or by using BitVecs instead of BitSlices.

Type Parameters

  • I: IntoIterator<Item=bool, IntoIter: DoubleEndedIterator>: The bitstream to add into self. It must be finite and double-ended, since addition operates in reverse.

fn add_assign(&mut self, addend: I)[src]

Performs unsigned wrapping addition in place.

Examples

This example shows addition of a slice wrapping from max to zero.

use bitvec::prelude::*;

let mut src = [0b1110_1111u8, 0b0000_0001];
let bits = src.as_mut_bitslice::<BigEndian>();
let (nums, one) = bits.split_at_mut(12);
let (accum, steps) = nums.split_at_mut(4);
*accum += &*one;
assert_eq!(accum, &steps[.. 4]);
*accum += &*one;
assert_eq!(accum, &steps[4 ..]);

impl<'a, C, T> Not for &'a mut BitSlice<C, T> where
    C: Cursor,
    T: 'a + BitStore
[src]

Flips all bits in the slice, in place.

type Output = Self

The resulting type after applying the ! operator.

fn not(self) -> Self::Output[src]

Inverts all bits in the slice.

This will not affect bits outside the slice in slice storage elements.

Parameters

  • self

Examples

use bitvec::prelude::*;

let mut src = [0u8; 2];
let bits = &mut src.as_mut_bitslice::<BigEndian>()[2 .. 14];
let new_bits = !bits;
//  The `bits` binding is consumed by the `!` operator, and a new
//  reference is returned.
// assert_eq!(bits.as_ref(), &[!0, !0]);
assert_eq!(new_bits.as_ref(), &[0x3F, 0xFC]);

impl<C, T, I> BitAndAssign<I> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore,
    I: IntoIterator<Item = bool>, 
[src]

Performs the Boolean AND operation against another bitstream and writes the result into self. If the other bitstream ends before self,, the remaining bits of self are cleared.

Type Parameters

  • I: IntoIterator<Item=bool>: A stream of bits, which may be a BitSlice or some other bit producer as desired.

fn bitand_assign(&mut self, rhs: I)[src]

ANDs a bitstream into a slice.

Parameters

  • &mut self
  • rhs: The bitstream to AND into self.

Examples

use bitvec::prelude::*;

let mut store = [0b0101_0100u8];
let     other = [0b0011_0000u8];
let lhs = store.as_mut_bitslice::<BigEndian>();
let rhs = other.as_bitslice::<BigEndian>();
lhs[.. 6] &= &rhs[.. 4];
assert_eq!(store[0], 0b0001_0000);

impl<C, T, I> BitOrAssign<I> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore,
    I: IntoIterator<Item = bool>, 
[src]

Performs the Boolean OR operation against another bitstream and writes the result into self. If the other bitstream ends before self, the remaining bits of self are not affected.

Type Parameters

  • I: IntoIterator<Item=bool>: A stream of bits, which may be a BitSlice or some other bit producer as desired.

fn bitor_assign(&mut self, rhs: I)[src]

ORs a bitstream into a slice.

Parameters

  • &mut self
  • rhs: The bitstream to OR into self.

Examples

use bitvec::prelude::*;

let mut store = [0b0101_0100u8];
let     other = [0b0011_0000u8];
let lhs = store.as_mut_bitslice::<BigEndian>();
let rhs = other.as_bitslice::<BigEndian>();
lhs[.. 6] |= &rhs[.. 4];
assert_eq!(store[0], 0b0111_0100);

impl<C, T, I> BitXorAssign<I> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore,
    I: IntoIterator<Item = bool>, 
[src]

Performs the Boolean XOR operation against another bitstream and writes the result into self. If the other bitstream ends before self, the remaining bits of self are not affected.

Type Parameters

  • I: IntoIterator<Item=bool>: A stream of bits, which may be a BitSlice or some other bit producer as desired.

fn bitxor_assign(&mut self, rhs: I)[src]

XORs a bitstream into a slice.

Parameters

  • &mut self
  • rhs: The bitstream to XOR into self.

Examples

use bitvec::prelude::*;

let mut store = [0b0101_0100u8];
let     other = [0b0011_0000u8];
let lhs = store.as_mut_bitslice::<BigEndian>();
let rhs = other.as_bitslice::<BigEndian>();
lhs[.. 6] ^= &rhs[.. 4];
assert_eq!(store[0], 0b0110_0100);

impl<C, T> ShlAssign<usize> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

Shifts all bits in the array to the left — DOWN AND TOWARDS THE FRONT.

On primitives, the left-shift operator << moves bits away from the origin and towards the ceiling. This is because we label the bits in a primitive with the minimum on the right and the maximum on the left, which is big-endian bit order. This increases the value of the primitive being shifted.

THAT IS NOT HOW BitSlice WORKS!

BitSlice defines its layout with the minimum on the left and the maximum on the right! Thus, left-shifting moves bits towards the minimum.

In BigEndian order, the effect in memory will be what you expect the << operator to do.

In LittleEndian order, the effect will be equivalent to using >> on the primitives in memory!

Notes

In order to preserve the effecs in memory that this operator traditionally expects, the bits that are emptied by this operation are zeroed rather than left to their old value.

The shift amount is modulated against the array length, so it is not an error to pass a shift amount greater than the array length.

A shift amount of zero is a no-op, and returns immediately.

fn shl_assign(&mut self, shamt: usize)[src]

Shifts a slice left, in place.

Parameters

  • &mut self
  • shamt: The shift amount. If this is greater than the length, then the slice is zeroed immediately.

Examples

use bitvec::prelude::*;

let mut src = [0x4Bu8, 0xA5];
let bits = &mut src.as_mut_bitslice::<BigEndian>()[2 .. 14];
*bits <<= 3;
assert_eq!(bits.as_ref(), &[0b01_011_101, 0b001_000_01]);

impl<C, T> ShrAssign<usize> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

Shifts all bits in the array to the right — UP AND TOWARDS THE BACK.

On primitives, the right-shift operator >> moves bits towards the origin and away from the ceiling. This is because we label the bits in a primitive with the minimum on the right and the maximum on the left, which is big-endian bit order. This decreases the value of the primitive being shifted.

THAT IS NOT HOW BitSlice WORKS!

BitSlice defines its layout with the minimum on the left and the maximum on the right! Thus, right-shifting moves bits towards the maximum.

In Big-Endian order, the effect in memory will be what you expect the >> operator to do.

In LittleEndian order, the effect will be equivalent to using << on the primitives in memory!

Notes

In order to preserve the effects in memory that this operator traditionally expects, the bits that are emptied by this operation are zeroed rather than left to their old value.

The shift amount is modulated against the array length, so it is not an error to pass a shift amount greater than the array length.

A shift amount of zero is a no-op, and returns immediately.

fn shr_assign(&mut self, shamt: usize)[src]

Shifts a slice right, in place.

Parameters

  • &mut self
  • shamt: The shift amount. If this is greater than the length, then the slice is zeroed immediately.

Examples

use bitvec::prelude::*;

let mut src = [0x4Bu8, 0xA5];
let bits = &mut src.as_mut_bitslice::<BigEndian>()[2 .. 14];
*bits >>= 3;
assert_eq!(bits.as_ref(), &[0b01_000_00_1, 0b011_101_01])

impl<C, T> Index<usize> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

Indexes a single bit by semantic count. The index must be less than the length of the BitSlice.

type Output = bool

The returned type after indexing.

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

Looks up a single bit by semantic index.

Parameters

  • &self
  • index: The semantic index of the bit to look up.

Returns

The value of the bit at the requested index.

Examples

use bitvec::prelude::*;

let src = 0b0010_0000u8;
let bits = src.as_bitslice::<BigEndian>();
assert!(bits[2]);
assert!(!bits[3]);

impl<C, T> Index<Range<usize>> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

type Output = Self

The returned type after indexing.

impl<C, T> Index<RangeInclusive<usize>> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

type Output = Self

The returned type after indexing.

impl<C, T> Index<RangeFrom<usize>> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

type Output = Self

The returned type after indexing.

impl<C, T> Index<RangeFull> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

type Output = Self

The returned type after indexing.

impl<C, T> Index<RangeTo<usize>> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

type Output = Self

The returned type after indexing.

impl<C, T> Index<RangeToInclusive<usize>> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

type Output = Self

The returned type after indexing.

impl<C, T> IndexMut<Range<usize>> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<C, T> IndexMut<RangeInclusive<usize>> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<C, T> IndexMut<RangeFrom<usize>> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<C, T> IndexMut<RangeFull> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<C, T> IndexMut<RangeTo<usize>> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<C, T> IndexMut<RangeToInclusive<usize>> for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<C, T> Hash for BitSlice<C, T> where
    C: Cursor,
    T: BitStore
[src]

Writes the contents of the BitSlice, in semantic bit order, into a hasher.

fn hash<H>(&self, hasher: &mut H) where
    H: Hasher
[src]

Writes each bit of the BitSlice, as a full bool, into the hasher.

Parameters

  • &self
  • hasher: The hashing state into which the slice will be written.

Type Parameters

  • H: Hasher: The type of the hashing algorithm which receives the bits of self.

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

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

impl<C, T> BorrowMut<BitSlice<C, T>> for BitBox<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<C, T> BorrowMut<BitSlice<C, T>> for BitVec<C, T> where
    C: Cursor,
    T: BitStore
[src]

Signifies that BitSlice is the borrowed form of BitVec.

fn borrow_mut(&mut self) -> &mut BitSlice<C, T>[src]

Mutably borrows the BitVec as a BitSlice.

Parameters

  • &mut self

Returns

A mutably borrowed BitSlice of the vector.

Examples

use bitvec::prelude::*;
use std::borrow::BorrowMut;

let mut bv = bitvec![0; 13];
let bs: &mut BitSlice = bv.borrow_mut();
assert!(!bs[10]);
bs.set(10, true);
assert!(bs[10]);

impl<C, T> Borrow<BitSlice<C, T>> for BitBox<C, T> where
    C: Cursor,
    T: BitStore
[src]

impl<C, T> Borrow<BitSlice<C, T>> for BitVec<C, T> where
    C: Cursor,
    T: BitStore
[src]

Signifies that BitSlice is the borrowed form of BitVec.

fn borrow(&self) -> &BitSlice<C, T>[src]

Borrows the BitVec as a BitSlice.

Parameters

  • &self

Returns

A borrowed BitSlice of the vector.

Examples

use bitvec::prelude::*;
use std::borrow::Borrow;

let bv = bitvec![0; 13];
let bs: &BitSlice = bv.borrow();
assert!(!bs[10]);

impl<C, T> Serialize for BitSlice<C, T> where
    C: Cursor,
    T: BitStore + Serialize
[src]

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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

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

impl<T> From<T> 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.

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

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

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