[][src]Struct bitvec::BitBox

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

A pointer type for owned bit sequences.

This type is essentially a &BitSlice that owns its own memory. It can change the contents of its domain, but it cannot change its own domain like BitVec can. It is useful for fixed-size collections without lifetime tracking.

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: Bits: An implementor of the Bits trait: u8, u16, u32, or u64. This is the actual type in memory that the box will use to store data.

Safety

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

Trait Implementations

BitBox<C, T> implements all the traits that BitSlice<C, T> does, by deferring to the BitSlice implementation. It also implements conversion traits to and from BitSlice, and to/from BitVec.

Methods

impl<C, T> BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

pub fn uninhabited(data: *const T) -> Self[src]

Constructs an empty slice at a given location.

Parameters

  • data: The address of the empty BitBox to construct.

Returns

An empty BitBox at the given location.

pub fn new(src: &BitSlice<C, T>) -> Self[src]

Copies a BitSlice into an owned BitBox.

Parameters

  • src: The &BitSlice to make owned.

Returns

An owned clone of the given bit slice.

pub unsafe fn from_raw(pointer: BitPtr<T>) -> Self[src]

Constructs a BitBox from a raw BitPtr.

After calling this function, the raw pointer is owned by the resulting BitBox. The BitBox will deallocate the memory region it describes.

Parameters

  • pointer: A BitPtr<T> describing a region of owned memory. This must have previously produced by BitBox constructors; it is unsound to even pass in BitPtr<T> values taken from BitVec<C, T> handles.

Returns

An owned BitBox over the given pointer.

Safety

Because Rust does not specify the allocation scheme used, the only valid pointer to pass into this function is one that had previously been produced by BitBox constructors and extracted by BitBox::into_raw.

This function is unsafe because improper use can lead to double-free errors (constructing multiple BitBoxes from the same BitPtr) or allocator inconsistencies (arbitrary pointers).

pub unsafe fn into_raw(b: BitBox<C, T>) -> BitPtr<T>[src]

Consumes the BitBox, returning the wrapped BitPtr directly.

After calling this function, the caller is responsible for the memory previously managed by the BitBox. In particular, the caller must properly release the memory region to which the BitPtr refers. The proper way to do so is to convert the BitPtr back into a BitBox with the BitBox::from_raw function.

Note: this is an associated function, which means that you must call it as BitBox::into_raw(b) instead of b.into_raw(). This is to match the API of Box; there is no method conflict with BitSlice.

pub fn leak<'a>(b: BitBox<C, T>) -> &'a mut BitSlice<C, T>[src]

Consumes and leaks the BitBox, returning a mutable reference, &'a mut BitSlice<C, T>. Note that the memory region [T] must outlive the chosen lifetime 'a.

This function is mainly useful for bit regions that live for the remainder of the program’s life. Dropping the returned reference will cause a memory leak. If this is not acceptable, the reference should first be wrapped with the Box::from_raw function, producing a BitBox. This BitBox can then be dropped which will properly deallocate the memory.

Note: this is an associated function, which means that you must call it as BitBox::leak(b) instead of b.leak(). This is to match the API of Box; there is no method conflict with BitSlice.

Parameters

  • b: The BitBox to deconstruct.

Returns

The raw pointer from inside the BitBox.

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

Accesses the BitSlice<C, T> to which the BitBox refers.

Parameters

  • &self

Returns

The slice of bits behind the box.

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

Accesses the BitSlice<C, T> to which the BitBox refers.

Parameters

  • &mut self

Returns

The slice of bits behind the box.

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

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::*;

let store: &[u8] = &[0];
let bv: &BitSlice = store.into();
assert_eq!(bv.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::*;

let bv: &BitSlice = BitSlice::empty();
assert!(bv.is_empty());
let bv: &BitSlice = (&[0u8] as &[u8]).into();;
assert!(!bv.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::*;

assert!(BitSlice::<BigEndian, u8>::empty().first().is_none());
let bv: &BitSlice = (&[128u8] as &[u8]).into();
assert!(bv.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::*;

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

let store: &[u8] = &[128];
let bv: &BitSlice = store.into();
let (h, t) = bv.split_first().unwrap();
assert!(h);
assert!(t.not_any());

let bv = &bv[0 .. 1];
let (h, t) = bv.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)

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::*;

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

let bv: &BitSlice = (&[1u8] as &[u8]).into();
let (t, h) = bv.split_last().unwrap();
assert!(t);
assert!(h.not_any());

let bv = &bv[7 .. 8];
let (t, h) = bv.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)

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::*;

assert!(BitSlice::<BigEndian, u8>::empty().last().is_none());
let bv: &BitSlice = (&[1u8] as &[u8]).into();
assert!(bv.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.

Examples

use bitvec::*;

let bv: &BitSlice = (&[8u8] as &[u8]).into();
assert!(bv.get(4).unwrap());
assert!(!bv.get(3).unwrap());
assert!(bv.get(10).is_none());

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::*;

let store: &mut [u8] = &mut [8u8];
let bv: &mut BitSlice = store.into();
assert!(!bv[3]);
bv.set(3, true);
assert!(bv[3]);

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.

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::*;

let store: &[u8] = &[0; 4];
let bv: &BitSlice = store.into();
assert_eq!(store.as_ptr(), bv.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.

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::*;

let store: &mut [u8] = &mut[0; 4];
let store_ptr = store.as_mut_ptr();
let bv: &mut BitSlice = store.into();
assert_eq!(store_ptr, bv.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::*;

let store: &mut [u8] = &mut[32u8];
let bv: &mut BitSlice = store.into();
assert!(!bv[0]);
assert!(bv[2]);
bv.swap(0, 2);
assert!(bv[0]);
assert!(!bv[2]);

pub fn reverse(&mut self)[src]

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

Parameters

  • &mut self

Examples

use bitvec::*;

let store: &mut [u8] = &mut[0b1010_1010];
{
  let bv: &mut BitSlice = store.into();
  bv[1 .. 7].reverse();
}
eprintln!("{:b}", store[0]);
assert_eq!(store[0], 0b1101_0100);

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::*;

let store: &[u8] = &[64];
let bv: &BitSlice = store.into();
let mut iter = bv[.. 2].iter();
assert!(!iter.next().unwrap());
assert!(iter.next().unwrap());
assert!(iter.next().is_none());

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::*;

let store: &[u8] = &[0b0100_1011];
let bv: &BitSlice = store.into();
let mut windows = bv.windows(4);
assert_eq!(windows.next(), Some(&bv[0 .. 4]));
assert_eq!(windows.next(), Some(&bv[1 .. 5]));
assert_eq!(windows.next(), Some(&bv[2 .. 6]));
assert_eq!(windows.next(), Some(&bv[3 .. 7]));
assert_eq!(windows.next(), Some(&bv[4 .. 8]));
assert!(windows.next().is_none());

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::*;

let store: &[u8] = &[0b0100_1011];
let bv: &BitSlice = store.into();
let mut chunks = bv.chunks(3);
assert_eq!(chunks.next(), Some(&bv[0 .. 3]));
assert_eq!(chunks.next(), Some(&bv[3 .. 6]));
assert_eq!(chunks.next(), Some(&bv[6 .. 8]));
assert!(chunks.next().is_none());

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.

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::*;

let store: &[u8] = &[0b0100_1011];
let bv: &BitSlice = store.into();
let mut chunks_exact = bv.chunks_exact(3);
assert_eq!(chunks_exact.next(), Some(&bv[0 .. 3]));
assert_eq!(chunks_exact.next(), Some(&bv[3 .. 6]));
assert!(chunks_exact.next().is_none());
assert_eq!(chunks_exact.remainder(), &bv[6 .. 8]);

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.

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::*;

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

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.

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::*;

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

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.

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::*;

let store: &[u8] = &[0x0F];
let bv: &BitSlice = store.into();

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

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

let (l, r) = bv.split_at(8);
assert_eq!(l, bv);
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: Bits
[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::*;

let store: &[u8] = &[0xA6];
let bv: &BitSlice = store.into();;
assert!(bv.starts_with(&bv[.. 3]));
assert!(!bv.starts_with(&bv[3 ..]));

pub fn ends_with<D, U>(&self, suffix: &BitSlice<D, U>) -> bool where
    D: Cursor,
    U: Bits
[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::*;

let store: &[u8] = &[0xA6];
let bv: &BitSlice = store.into();
assert!(bv.ends_with(&bv[5 ..]));
assert!(!bv.ends_with(&bv[.. 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::*;

let store: &mut [u8] = &mut [0xF0];
let bv: &mut BitSlice = store.into();
bv.rotate_left(2);
assert_eq!(bv.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::*;

let store: &mut [u8] = &mut [0xF0];
let bv: &mut BitSlice = store.into();
bv.rotate_right(2);
assert_eq!(bv.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.

Examples

use bitvec::*;

let store: &[u8] = &[0xFD];
let bv: &BitSlice = store.into();
assert!(bv[.. 4].all());
assert!(!bv[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.

Examples

use bitvec::*;

let store: &[u8] = &[0x40];
let bv: &BitSlice = store.into();
assert!(bv[.. 4].any());
assert!(!bv[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::*;

let store: &[u8] = &[0xFD];
let bv: &BitSlice = store.into();
assert!(!bv[.. 4].not_all());
assert!(bv[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::*;

let store: &[u8] = &[0x40];
let bv: &BitSlice = store.into();
assert!(!bv[.. 4].not_any());
assert!(bv[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.

Examples

use bitvec::*;

let store: &[u8] = &[0b111_000_10];
let bv: &BitSlice = store.into();
assert!(!bv[0 .. 3].some());
assert!(!bv[3 .. 6].some());
assert!(bv[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::*;

let store: &[u8] = &[0xFD, 0x25];
let bv: &BitSlice = store.into();
assert_eq!(bv.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::*;

let store: &[u8] = &[0xFD, 0x25];
let bv: &BitSlice = store.into();
assert_eq!(bv.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::*;

let store: &mut [u8] = &mut [0];
let bv: &mut BitSlice = store.into();
bv[2 .. 6].set_all(true);
assert_eq!(bv.as_ref(), &[0b0011_1100]);
bv[3 .. 5].set_all(false);
assert_eq!(bv.as_ref(), &[0b0010_0100]);
bv[.. 1].set_all(true);
assert_eq!(bv.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::*;

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

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

Accesses the underlying store.

Examples

use bitvec::*;

let mut bv: BitVec = bitvec![0, 0, 0, 0, 0, 0, 0, 0, 1];
for elt in bv.as_mut_slice() {
  *elt += 2;
}
assert_eq!(&[2, 0b1000_0010], bv.as_slice());

pub fn head(&self) -> Option<&T>[src]

pub fn head_mut(&mut self) -> Option<&mut T>[src]

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

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

pub fn tail(&self) -> Option<&T>[src]

pub fn tail_mut(&mut self) -> Option<&mut T>[src]

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> Drop for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

impl<C, T> Eq for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

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

#[must_use]
default 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]
default 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]
default 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]
default 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: Bits,
    C: Cursor,
    D: Bits
[src]

#[must_use]
default 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]
default 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]
default 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]
default 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: Bits,
    C: Cursor,
    D: Bits
[src]

#[must_use]
default 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]
default 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]
default 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]
default 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, T> AsMut<BitSlice<C, T>> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

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

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

#[must_use]
default 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: Bits,
    C: Cursor,
    D: Bits
[src]

#[must_use]
default 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: Bits,
    C: Cursor,
    D: Bits
[src]

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

This method tests for !=.

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

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

impl<C, T> Clone for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

default fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<C, T> Default for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

impl<C, T> Ord for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

default fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

default fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

default 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, '_> From<&'_ BitSlice<C, T>> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

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

Builds a BitBox out of a borrowed slice of elements.

This copies the memory as-is from the source buffer into the new BitBox. The source buffer will be unchanged by this operation, so you don't need to worry about using the correct cursor type for the read.

This operation does a copy from the source buffer into a new allocation, as it can only borrow the source and not take ownership.

fn from(src: &[T]) -> Self[src]

Builds a BitBox<C: Cursor, T: Bits> from a borrowed &[T].

Parameters

  • src: The elements to use as the values for the new vector.

Examples

use bitvec::*;

let src: &[u8] = &[5, 10];
let bv: BitBox = src.into();
assert!(bv[5]);
assert!(bv[7]);
assert!(bv[12]);
assert!(bv[14]);

impl<C, T> From<BitVec<C, T>> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

impl<C, T> From<Box<[T]>> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

Builds a BitBox out of an owned slice of elements.

This moves the memory as-is from the source buffer into the new BitBox. The source buffer will be unchanged by this operation, so you don't need to worry about using the correct cursor type.

fn from(src: Box<[T]>) -> Self[src]

Consumes a Box<[T: Bits]> and creates a BitBox<C: Cursor, T> from it.

Parameters

  • src: The source box whose memory will be used.

Returns

A new BitBox using the src Box’s memory.

Examples

use bitvec::*;

let src: Box<[u8]> = Box::new([3, 6, 9, 12, 15]);
let bv: BitBox = src.into();

impl<C, T> From<BitBox<C, T>> for BitVec<C, T> where
    C: Cursor,
    T: Bits
[src]

impl<C, T> IntoIterator for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

type Item = bool

The type of the elements being iterated over.

type IntoIter = IntoIter<C, T>

Which kind of iterator are we turning this into?

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

type Item = bool

The type of the elements being iterated over.

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

Which kind of iterator are we turning this into?

impl<C, T> Into<Box<[T]>> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

impl<C, T> Debug for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

impl<C, T> DerefMut for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

impl<C, T> Deref for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

type Target = BitSlice<C, T>

The resulting type after dereferencing.

impl<C, T> Hash for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

default 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> Add<BitBox<C, T>> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

type Output = Self

The resulting type after applying the + operator.

impl<C, T> Neg for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

type Output = Self

The resulting type after applying the - operator.

impl<C, T> AddAssign<BitBox<C, T>> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

impl<C, T> Not for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

type Output = Self

The resulting type after applying the ! operator.

impl<C, T, I> BitAnd<I> for BitBox<C, T> where
    C: Cursor,
    T: Bits,
    I: IntoIterator<Item = bool>, 
[src]

type Output = Self

The resulting type after applying the & operator.

impl<C, T, I> BitOr<I> for BitBox<C, T> where
    C: Cursor,
    T: Bits,
    I: IntoIterator<Item = bool>, 
[src]

type Output = Self

The resulting type after applying the | operator.

impl<C, T, I> BitXor<I> for BitBox<C, T> where
    C: Cursor,
    T: Bits,
    I: IntoIterator<Item = bool>, 
[src]

type Output = Self

The resulting type after applying the ^ operator.

impl<C, T> Shl<usize> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

type Output = Self

The resulting type after applying the << operator.

impl<C, T> Shr<usize> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

type Output = Self

The resulting type after applying the >> operator.

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

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

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

impl<C, T> ShlAssign<usize> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

impl<C, T> ShrAssign<usize> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

impl<C, T> Index<usize> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

type Output = bool

The returned type after indexing.

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

type Output = BitSlice<C, T>

The returned type after indexing.

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

type Output = BitSlice<C, T>

The returned type after indexing.

impl<C, T> Index<RangeFull> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

type Output = BitSlice<C, T>

The returned type after indexing.

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

type Output = BitSlice<C, T>

The returned type after indexing.

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

type Output = BitSlice<C, T>

The returned type after indexing.

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

type Output = BitSlice<C, T>

The returned type after indexing.

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

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

impl<C, T> IndexMut<RangeFull> for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

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

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

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

impl<C, T> Display for BitBox<C, T> where
    C: Cursor,
    T: Bits
[src]

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

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

Auto Trait Implementations

impl<C = BigEndian, T = u8> !Send for BitBox<C, T>

impl<C = BigEndian, T = u8> !Sync for BitBox<C, T>

Blanket Implementations

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

type Owned = T

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

impl<T> From for 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, U> Into for T where
    U: From<T>, 
[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

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

The type returned in the event of a conversion error.