Struct bitvec::boxed::BitBox [−][src]
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
O: BitOrder
: An implementor of theBitOrder
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 theBitStore
trait:u8
,u16
,u32
, oru64
(64-bit systems only). 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<O, T>
implements all the traits that BitSlice<O, T>
does, by
deferring to the BitSlice
implementation. It also implements conversion traits
to and from BitSlice
, and to/from BitVec
.
Implementations
impl<O, T> BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
pub fn new(bits: &BitSlice<O, T>) -> Self
[src]
Allocates memory on the heap and then places bits
into it.
API Differences
Box::new
takes a T
by direct value, and is not implemented as a
means of cloning slices. As BitSlice
cannot be held by value, this
function clones the referent slice region into a new fixed-size heap
buffer.
Examples
let boxed = BitBox::new(0u8.bits::<Lsb0>());
pub fn pin(bits: &BitSlice<O, T>) -> Pin<Self> where
O: Unpin,
T: Unpin,
[src]
O: Unpin,
T: Unpin,
Constructs a new Pin<BitBox<O, T>>
.
BitSlice
is always Unpin
, so this has no actual immobility effect.
pub unsafe fn from_raw(raw: *mut BitSlice<O, T>) -> Self
[src]
Constructs a bit box from a raw bit pointer.
After calling this function, the raw pointer is owned by the resulting
BitBox
. Specifically, the BitBox
destructor will free the allocated
memory. For this to be safe, the memory must have been allocated by
BitBox
earlier in the program.
Safety
This function is unsafe because improper use may lead to memory problems. For example, a double-free may occurr if the function is called twice on the same raw pointer.
Notes
This function, and into_raw
, exchange ordinary raw pointers
*mut BitSlice<O, T>
. Values of these types can be created from, and
converted to, other region pointers such as *mut [T]
through ordinary
as
-casting.
This is valid in the Rust type system, but is incorrect at runtime. You
must not, ever, use as
to cast in either direction to or from a
BitSlice
pointer.
Examples
Recreate a BitBox
which was previously converted to a raw pointer
using BitBox::into_raw
:
let b = BitBox::new(0u8.bits::<Lsb0>()); let ptr = BitBox::into_raw(b); let b = unsafe { BitBox::<Lsb0, _>::from_raw(ptr) };
pub fn into_raw(b: Self) -> *mut BitSlice<O, T>
[src]
Consumes the BitBox
, returning a wrapped raw pointer.
The pointer will be properly aligned and non-null.
After calling this function, the caller is responsible for the memory
previously managed by the BitBox
. In particular, the caller should
properly release the memory by converting the pointer back into a
BitBox
with the BitBox::from_raw
function, allowing the BitBox
destructor to perform the cleanup.
Note: this is an associated function, which means that you have to call
it as BitBox::into_raw(b)
instead of b.into_raw()
. This is to match
layout with the standard library’s Box
API; there will never be a name
conflict with BitSlice
.
Notes
As with ::from_raw
, the pointer returned by this function must not
ever have its type or value changed or inspected in any way. It may only
be held and then passed into ::from_raw
in the future.
Examples
Converting the raw pointer back into a BitBox
with
BitBox::from_raw
for automatic cleanup:
let b = BitBox::new(0u64.bits::<Msb0>()); let ptr = BitBox::into_raw(b); let b = unsafe { BitBox::<Msb0, _>::from_raw(ptr) };
pub fn leak<'a>(self) -> &'a mut BitSlice<O, T>
[src]
Consumes and leaks the BitBox
, returning a mutable reference,
&'a mut BitSlice<O, 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 BitBox::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 have to call
it as BitBox::leak(b)
instead of b.leak()
. This is to match layout
with the standard library’s Box
API; there will never be a name
conflict with BitSlice
.
Examples
Simple usage:
let b = BitBox::new(0u64.bits::<Local>()); let static_ref: &'static mut BitSlice<Local, u64> = BitBox::leak(b); static_ref.set(0, true); assert_eq!(static_ref.count_ones(), 1);
impl<O, T> BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
pub fn empty() -> Self
[src]
Constructs an empty boxed bitslice.
Returns
An empty BitBox
at an arbitrary location.
Examples
use bitvec::prelude::*; let bb: BitBox = BitBox::empty(); assert!(bb.is_empty());
pub fn from_element(elt: T) -> Self
[src]
Produces a BitBox
from a single element.
Parameters
elt
: The source element from which to make theBitBox
.
Returns
A BitBox
containing the provided element.
Examples
use bitvec::prelude::*; let bb: BitBox<Msb0, u16> = BitBox::from_element(!0); assert!(bb.all());
pub fn from_slice(slice: &[T]) -> Self
[src]
Builds a BitBox
from a borrowed slice of elements.
Parameters
slice
: The source slice from which to make theBitBox
.
Returns
A BitBox
containing the (cloned) provided slice.
Panics
This function may panic if the provided slice is longer than the
BitBox
can support.
Examples
use bitvec::prelude::*; let src = [5, 10]; let bb: BitBox<Msb0, u8> = BitBox::from_slice(&src[..]); assert!(bb[5]); assert!(bb[7]); assert!(bb[12]); assert!(bb[14]);
pub fn from_bitslice(slice: &BitSlice<O, T>) -> Self
[src]
Clones a &BitSlice
into a BitBox
.
Parameters
slice
: The bit slice to clone into a bit box.
Returns
A BitBox
containing the same bits as the source slice.
Examples
use bitvec::prelude::*; let src = [0u8, !0]; let bb = BitBox::<Msb0, _>::from_bitslice(src.bits()); assert_eq!(bb.len(), 16); assert!(bb.some());
pub fn from_boxed_slice(boxed: Box<[T]>) -> Self
[src]
Produces a BitBox
from an owned slice of elements.
Parameters
slice
: The source boxed slice from which to make theBitBox
.
Returns
A BitBox
governing the same slice that was passed in. This function
does not reallocate.
Panics
This function may panic if the provided slice is longer than the
BitBox
can support.
Examples
use bitvec::prelude::*; let slice: Box<[u16]> = vec![0, !0].into_boxed_slice(); let bb = BitBox::<Lsb0, _>::from_boxed_slice(slice); assert!(bb.some()); assert_eq!(bb.len(), 32);
pub fn into_boxed_slice(self) -> Box<[T]>
[src]
Removes the BitBox
wrapper from a Box<[T]>
.
Parameters
self
Returns
The Box<[T]>
underneath self
.
Examples
use bitvec::prelude::*; let slice: Box<[u16]> = vec![0, !0].into_boxed_slice(); let bb = BitBox::<Lsb0, _>::from_boxed_slice(slice); assert_eq!(bb.len(), 32); let slice = bb.into_boxed_slice(); assert_eq!(slice.len(), 2);
pub fn add_reverse<I>(self, addend: I) -> Self where
I: IntoIterator<Item = bool>,
[src]
I: IntoIterator<Item = bool>,
Performs “reverse” addition (left to right instead of right to left).
This delegates to BitSlice::add_assign_reverse
.
Parameters
self
addend: impl IntoIterator<Item=bool>
: A bitstream to add toself
.
Returns
The sum of self
and addend
.
pub fn change_order<P>(self) -> BitBox<P, T> where
P: BitOrder,
[src]
P: BitOrder,
Changes the order on a box handle, without changing the data it governs.
Parameters
self
Returns
An equivalent handle to the same data, with a new order parameter.
pub fn as_bitslice(&self) -> &BitSlice<O, T>
[src]
Accesses the BitSlice<O, 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<O, T>
[src]
Accesses the BitSlice<O, T>
to which the BitBox
refers.
Parameters
&mut self
Returns
The slice of bits behind the box.
pub fn as_slice(&self) -> &[T]
[src]
Accesses the vector’s backing store as an element slice.
Unlike BitSlice
’s method of the same name, this includes the partial
edges, as BitBox
forbids fragmentation that leads to contention.
Parameters
&self
Returns
The slice of all live elements in the backing storage, including the partial edges if present.
pub fn as_mut_slice(&mut self) -> &mut [T]
[src]
Accesses the vector’s backing store as an element slice.
Unlike BitSlice
’s method of the same name, this includes the partial
edges, as BitBox
forbids fragmentation that leads to contention.
Parameters
&mut self
Returns
The slice of all live elements in the backing storage, including the partial edges if present.
Methods from Deref<Target = BitSlice<O, T>>
pub fn len(&self) -> usize
[src]
Returns the number of bits in the slice.
Original
Examples
let bits = 0u8.bits::<Local>(); assert_eq!(bits.len(), 8);
pub fn is_empty(&self) -> bool
[src]
Returns true
if the slice has a length of 0.
Original
Examples
let bits = 0u8.bits::<Local>(); assert!(!bits.is_empty()); assert!(BitSlice::<Local, usize>::empty().is_empty())
pub fn first(&self) -> Option<&bool>
[src]
Returns the first bit of the slice, or None
if it is empty.
Original
Examples
let bits = 1u8.bits::<Lsb0>(); assert_eq!(bits.first(), Some(&true)); assert!(BitSlice::<Local, usize>::empty().first().is_none());
pub fn first_mut(&mut self) -> Option<BitMut<'_, O, T>>
[src]
Returns a mutable pointer to the first bit of the slice, or None
if it
is empty.
Original
Examples
let mut data = 0u8; let bits = data.bits_mut::<Lsb0>(); if let Some(mut first) = bits.first_mut() { *first = true; } assert_eq!(data, 1u8);
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.
Examples
let bits = 1u8.bits::<Lsb0>(); if let Some((first, rest)) = bits.split_first() { assert_eq!(first, &true); assert_eq!(rest, &bits[1 ..]); }
pub fn split_first_mut(&mut self) -> Option<(BitMut<'_, O, T>, &mut Self)>
[src]
Returns the first and all the rest of the bits of the slice, or None
if it is empty.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Lsb0>(); if let Some((mut first, rest)) = bits.split_first_mut() { *first = true; *rest.at(0) = true; *rest.at(1) = true; } assert_eq!(data, 7);
pub fn split_last(&self) -> Option<(&bool, &Self)>
[src]
Returns the last and all the rest of the bits of the slice, or None
if
it is empty.
Examples
let bits = 1u8.bits::<Msb0>(); if let Some((last, rest)) = bits.split_last() { assert_eq!(last, &true); assert_eq!(rest, &bits[.. 7]); }
pub fn split_last_mut(&mut self) -> Option<(BitMut<'_, O, T>, &mut Self)>
[src]
Returns the last and all the rest of the bits of the slice, or None
if
it is empty.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Msb0>(); if let Some((mut last, rest)) = bits.split_last_mut() { *last = true; *rest.at(0) = true; *rest.at(1) = true; } assert_eq!(data, 128 | 64 | 1);
pub fn last(&self) -> Option<&bool>
[src]
Returns the last bit of the slice, or None
if it is empty.
Examples
let bits = 1u8.bits::<Msb0>(); assert_eq!(Some(&true), bits.last()); assert!(BitSlice::<Local, usize>::empty().last().is_none());
pub fn last_mut(&mut self) -> Option<BitMut<'_, O, T>>
[src]
Returns a mutable pointer to the last bit in the slice.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Msb0>(); if let Some(mut last) = bits.last_mut() { *last = true; } assert!(bits[7]);
pub fn get<'a, I>(&'a self, index: I) -> Option<I::Immut> where
I: BitSliceIndex<'a, O, T>,
[src]
I: BitSliceIndex<'a, O, T>,
Returns a reference to a bit or subslice depending on the type of
index
.
- If given a position, returns a reference to the bit at that position
or
None
if out of bounds. - If given a range, returns the subslice corresponding to that range, or
None
if out of bounds.
Examples
let data = 1u8; let bits = data.bits::<Lsb0>(); assert_eq!(Some(&true), bits.get(0)); assert!(bits.get(8).is_none()); assert!(bits.get(1 ..).expect("in bounds").not_any()); assert!(bits.get(.. 12).is_none());
pub fn get_mut<'a, I>(&'a mut self, index: I) -> Option<I::Mut> where
I: BitSliceIndex<'a, O, T>,
[src]
I: BitSliceIndex<'a, O, T>,
Returns a mutable reference to a bit or subslice depending on the type
of index
(see get
) or None
if the index is out of bounds.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Lsb0>(); if let Some(mut bit) = bits.get_mut(1) { *bit = true; } if let Some(bits) = bits.get_mut(5 .. 7) { bits.set_all(true); } assert_eq!(data, 64 | 32 | 2);
pub unsafe fn get_unchecked<'a, I>(&'a self, index: I) -> I::Immut where
I: BitSliceIndex<'a, O, T>,
[src]
I: BitSliceIndex<'a, O, T>,
Returns a reference to a bit or subslice, without doing bounds checking.
This is generally not recommended; use with caution! For a safe
alternative, see get
.
Safety
As this function does not perform boundary checking, the caller must
ensure that self
is an index within the boundaries of slice
before
calling in order to avoid boundary escapes and ensuing safety
violations.
Examples
let data = 4u8; let bits = data.bits::<Lsb0>(); unsafe { assert!(bits.get_unchecked(2)); assert!(!bits.get_unchecked(1)); }
pub unsafe fn get_unchecked_mut<'a, I>(&'a mut self, index: I) -> I::Mut where
I: BitSliceIndex<'a, O, T>,
[src]
I: BitSliceIndex<'a, O, T>,
Returns a mutable reference to a bit or subslice, without doing bounds checking.
This is generally not recommended; use with caution! For a safe
alternative, see get_mut
.
Safety
As this function does not perform boundary checking, the caller must
ensure that self
is an index within the boundaries of slice
before
calling in order to avoid boundary escapes and ensuing safety
violations.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Msb0>(); unsafe { let mut bit = bits.get_unchecked_mut(0); *bit = true; drop(bit); // release the borrow immediately let bits = bits.get_unchecked_mut(6 ..); bits.set_all(true); } assert_eq!(data, 1 | 2 | 128);
pub fn as_ptr(&self) -> *const T
[src]
Returns a raw pointer to the slice’s buffer.
The caller must ensure that the slice outlives the pointer this function returns, or else it will end up pointing to garbage.
The caller must also ensure that the memory the pointer
(non-transitively) points to is never written to (except inside an
UnsafeCell
) using this pointer or any pointer derived from it. If you
need to mutate the contents of the buffer, use as_mut_ptr
.
Modifying the container referenced by this slice may cause its buffer to be reallocated, which would also make any pointers to it invalid.
Notes
This pointer is always to the first T
element in the backing storage,
even if that element is only partially used by the self
slice.
Multiple separate BitSlice
handles may produce the same pointer with
this method.
Examples
let data = [0u8; 2]; let bits = data.bits::<Msb0>(); let (head, rest) = bits.split_at(4); assert_eq!(head.as_ptr(), rest.as_ptr());
pub fn as_mut_ptr(&mut self) -> *mut T
[src]
Returns an unsafe mutable pointer to the slice’s buffer.
The caller must ensure thath the slice outlives the pointer this function returns, or else it will end up pointing to garbage.
Modifying the container referenced by this slice may couse its buffer to be reallocated, which would also make any pointers to it invalid.
Notes
This pointer is always to the first T
element in the backing storage,
even if that element is only partially used by the self
slice.
Multiple separate BitSlice
handles may produce the same pointer with
this method.
Examples
let mut data = [0u8; 2]; let bits = data.bits_mut::<Msb0>(); let (head, rest) = bits.split_at_mut(4); assert_eq!(head.as_mut_ptr(), rest.as_mut_ptr()); unsafe { *head.as_mut_ptr() = 2; } assert!(rest[2]);
pub fn swap(&mut self, a: usize, b: usize)
[src]
Swaps two bits in the slice.
Arguments
a
: The index of the first bitb
: The index of the second bit
Panics
Panics if a
or b
are out of bounds.
Examples
let mut data = 2u8; let bits = data.bits_mut::<Lsb0>(); bits.swap(0, 1); assert_eq!(data, 1);
pub fn reverse(&mut self)
[src]
Reverses the order of bits in the slice, in place.
Examples
use bitvec::prelude::*; let mut data = 0b1_1001100u8; let bits = data.bits_mut::<Msb0>(); bits[1 ..].reverse(); assert_eq!(data, 0b1_0011001);
pub fn iter(&self) -> Iter<'_, O, T>ⓘ
[src]
Returns an iterator over the slice.
Examples
let data = 3u8; let bits = data.bits::<Lsb0>(); let mut iter = bits[.. 4].iter(); assert_eq!(iter.next(), Some(&true)); assert_eq!(iter.next(), Some(&true)); assert_eq!(iter.next(), Some(&false)); assert_eq!(iter.next(), Some(&false)); assert!(iter.next().is_none());
pub fn iter_mut(&mut self) -> IterMut<'_, O, T>ⓘ
[src]
Returns an iterator that allows modifying each bit.
Examples
let mut data = 0u8; let bits = &mut data.bits_mut::<Lsb0>()[.. 2]; for mut bit in bits.iter_mut() { *bit = true; } assert_eq!(data, 3);
pub fn windows(&self, width: usize) -> Windows<'_, O, T>ⓘ
[src]
Returns an iterator over all contiguous windows of width width
.
The windows overlap. If the slice is shorter than width
, the iterator
returns no values.
Panics
Panics if width
is 0.
Examples
let data = 0b100_010_01u8; let bits = data.bits::<Msb0>(); let mut iter = bits[.. 5].windows(3); assert_eq!(iter.next().unwrap(), &bits[0 .. 3]); assert_eq!(iter.next().unwrap(), &bits[1 .. 4]); assert_eq!(iter.next().unwrap(), &bits[2 .. 5]); assert!(iter.next().is_none());
If the slice is shorter than width
:
let data = 0u8; let bits = data.bits::<Local>(); let mut iter = bits[.. 3].windows(4); assert!(iter.next().is_none());
pub fn chunks(&self, chunk_size: usize) -> Chunks<'_, O, T>ⓘ
[src]
Returns an iterator over chunk_size
bits of the slice at a time,
starting at the beginning of the slice.
The chunks are slices and do not overlap. If chunk_size
does not
divide the length of the slice, then the last chunk will not have length
chunk_size
.
See chunks_exact
for a variant of this iterator that returns chunks
of always exactly chunk_size
elements, and rchunks
for the same
iterator but starting at the end of the slice.
Panics
Panics if chunk_size
is 0.
Examples
let data = 0b001_010_10u8; let bits = data.bits::<Msb0>(); let mut iter = bits.chunks(3); assert_eq!(iter.next().unwrap(), &bits[0 .. 3]); assert_eq!(iter.next().unwrap(), &bits[3 .. 6]); assert_eq!(iter.next().unwrap(), &bits[6 .. 8]); assert!(iter.next().is_none());
pub fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, O, T>ⓘ
[src]
Returns an iterator over chunk_size
bits of the slice at a time,
starting at the beginning of the slice.
The chunks are mutable slices, and do not overlap. If chunk_size
does
not divide the length of the slice, then the last chunk will not have
length chunk_size
.
See chunks_exact_mut
for a variant of this iterator that returns
chunks of always exactly chunk_size
bits, and rchunks_mut
for the
same iterator but starting at the end of the slice.
Panics
Panics if chunk_size
is 0.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Msb0>(); let mut count = 0; for chunk in bits.chunks_mut(3) { chunk.store(4u8 >> count); count += 1; } assert_eq!(count, 3); assert_eq!(data, 0b100_010_01);
pub fn chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, O, T>ⓘNotable traits for ChunksExact<'a, O, T>
impl<'a, O, T> Iterator for ChunksExact<'a, O, T> where
O: BitOrder,
T: 'a + BitStore, type Item = &'a BitSlice<O, T>;
[src]
Notable traits for ChunksExact<'a, O, T>
impl<'a, O, T> Iterator for ChunksExact<'a, O, T> where
O: BitOrder,
T: 'a + BitStore, type Item = &'a BitSlice<O, T>;
Returns an iterator over chunk_size
elements of the slice at a time,
starting at the beginning of the slice.
The chunks are slices and do not overlap. If chunk_size
does not
divide the length of the slice, then the last up to chunk_size - 1
elements will be omitted and can be retrieved from the remainder
function of the iterator.
Due to each chunk having exactly chunk_size
elements, the compiler can
often optimize the resulting code better than in the case of chunks
.
See chunks
for a variant of this iterator that also returns the
remainder as a smaller chunk, and rchunks_exact
for the same
iterator but starting at the end of the slice.
Panics
Panics if chunk_size
is 0.
Examples
let data = 0b100_010_01u8; let bits = data.bits::<Msb0>(); let mut iter = bits.chunks_exact(3); assert_eq!(iter.next().unwrap(), &bits[0 .. 3]); assert_eq!(iter.next().unwrap(), &bits[3 .. 6]); assert!(iter.next().is_none()); assert_eq!(iter.remainder(), &bits[6 .. 8]);
pub fn chunks_exact_mut(
&mut self,
chunk_size: usize
) -> ChunksExactMut<'_, O, T>ⓘNotable traits for ChunksExactMut<'a, O, T>
impl<'a, O, T> Iterator for ChunksExactMut<'a, O, T> where
O: BitOrder,
T: 'a + BitStore, type Item = &'a mut BitSlice<O, T>;
[src]
&mut self,
chunk_size: usize
) -> ChunksExactMut<'_, O, T>ⓘ
Notable traits for ChunksExactMut<'a, O, T>
impl<'a, O, T> Iterator for ChunksExactMut<'a, O, T> where
O: BitOrder,
T: 'a + BitStore, type Item = &'a mut BitSlice<O, T>;
Returns an iterator over chunk_size
elements of the slice at a time,
starting at the beginning of the slice.
The chunks are mutable slices, and do not overlap. If chunk_size
does
not divide the length of the slice, then the last up to chunk_size - 1
elements will be omitted and can be retrieved from the into_remainder
function of the iterator.
Due to each chunk having exactly chunk_size
elements, the compiler can
often optimize the resulting code better than in the case of
chunks_mut
.
See chunks_mut
for a variant of this iterator that also returns the
remainder as a smaller chunk, and rchunks_exact_mut
for the same
iterator but starting at the end of the slice of the slice.
Panics
Panics if chunk_size
is 0.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Msb0>(); let mut count = 0u8; let mut iter = bits.chunks_exact_mut(3); for chunk in &mut iter { chunk.store(4u8 >> count); count += 1; } iter.into_remainder().store(1u8); assert_eq!(count, 2); assert_eq!(data, 0b100_010_01);
pub fn rchunks(&self, chunk_size: usize) -> RChunks<'_, O, T>ⓘ
[src]
Returns an iterator over chunk_size
bits of the slice at a time,
starting at the end of the slice.
The chunks are slices and do not overlap. If chunk_size
does not
divide the length of the slice, then the last chunk will not have length
of the slice, then the last chunk will not have length chunk_size
.
See rchunks_exact
for a variant of this iterator that returns chunks
of always exactly chunk_size
bits, and chunks
for the same
iterator but starting at the beginning of the slice.
Panics
Panics if chunk_size
is 0.
Examples
let data = 0b01_010_100u8; let bits = data.bits::<Msb0>(); let mut iter = bits.rchunks(3); assert_eq!(iter.next().unwrap(), &bits[5 .. 8]); assert_eq!(iter.next().unwrap(), &bits[2 .. 5]); assert_eq!(iter.next().unwrap(), &bits[0 .. 2]); assert!(iter.next().is_none());
pub fn rchunks_mut(&mut self, chunk_size: usize) -> RChunksMut<'_, O, T>ⓘNotable traits for RChunksMut<'a, O, T>
impl<'a, O, T> Iterator for RChunksMut<'a, O, T> where
O: BitOrder,
T: 'a + BitStore, type Item = &'a mut BitSlice<O, T>;
[src]
Notable traits for RChunksMut<'a, O, T>
impl<'a, O, T> Iterator for RChunksMut<'a, O, T> where
O: BitOrder,
T: 'a + BitStore, type Item = &'a mut BitSlice<O, T>;
Returns an iterator over chunk_size
bits of the slice at a time,
starting at the end of the slice.
The chunks are mutable slices and do not overlap. If chunk_size
does
not divide the length of the slice, then the last chunk will not have
length of the slice, then the last chunk will not have length
chunk_size
.
See rchunks_exact_mut
for a variant of this iterator that returns
chunks of always exactly chunk_size
bits, and chunks_mut
for the
same iterator but starting at the beginning of the slice.
Panics
Panics if chunk_size
is 0.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Lsb0>(); let mut count = 0; for chunk in bits.rchunks_mut(3) { chunk.store(4u8 >> count); count += 1; } assert_eq!(count, 3); assert_eq!(data, 0b100_010_01);
pub fn rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, O, T>ⓘNotable traits for RChunksExact<'a, O, T>
impl<'a, O, T> Iterator for RChunksExact<'a, O, T> where
O: BitOrder,
T: 'a + BitStore, type Item = &'a BitSlice<O, T>;
[src]
Notable traits for RChunksExact<'a, O, T>
impl<'a, O, T> Iterator for RChunksExact<'a, O, T> where
O: BitOrder,
T: 'a + BitStore, type Item = &'a BitSlice<O, T>;
Returns an iterator over chunk_size
bits of the slice at a time,
starting at the end of the slice.
The chunks are slices and do not overlap. If chunk_size
does not
divide the length of the slice, then the last up to chunk_size - 1
bits will be omitted and can be retrieved from the remainder
function
of the iterator.
Due to each chunk having exactly chunk_size
bits, the compiler can
often optimize the resulting code better than in the case of chunks
.
See rchunks
for a variant of this iterator that also returns the
remainder as a smaller chunk, and chunks_exact
for the same iterator
but starting at the beginning of the slice.
Panics
Panics if chunk_size
is 0.
Examples
let data = 0b100_010_01u8; let bits = data.bits::<Lsb0>(); let mut iter = bits.rchunks_exact(3); assert_eq!(iter.next().unwrap(), &bits[5 .. 8]); assert_eq!(iter.next().unwrap(), &bits[2 .. 5]); assert!(iter.next().is_none()); assert_eq!(iter.remainder(), &bits[0 ..2]);
pub fn rchunks_exact_mut(
&mut self,
chunk_size: usize
) -> RChunksExactMut<'_, O, T>ⓘNotable traits for RChunksExactMut<'a, O, T>
impl<'a, O, T> Iterator for RChunksExactMut<'a, O, T> where
O: BitOrder,
T: 'a + BitStore, type Item = &'a mut BitSlice<O, T>;
[src]
&mut self,
chunk_size: usize
) -> RChunksExactMut<'_, O, T>ⓘ
Notable traits for RChunksExactMut<'a, O, T>
impl<'a, O, T> Iterator for RChunksExactMut<'a, O, T> where
O: BitOrder,
T: 'a + BitStore, type Item = &'a mut BitSlice<O, T>;
Returns an iterator over chunk_size
bits of the slice at a time,
starting at the end of the slice.
The chunks are mutable slices, and do not overlap. If chunk_size
does
not divide the length of the slice, then the last up to chunk_size - 1
bits will be omitted and can be retrieved from the into_remainder
function of the iterator.
Due to each chunk having exactly chunk_size
bits, the compiler can
often optimize the resulting code better than in the case of
chunks_mut
.
See rchunks_mut
for a variant of this iterator that also returns the
remainder as a smaller chunk, and chunks_exact_mut
for the same
iterator but starting at the beginning of the slice.
Panics
Panics if chunk_size
is 0.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Lsb0>(); let mut count = 0; let mut iter = bits.rchunks_exact_mut(3); for chunk in &mut iter { chunk.store(4u8 >> count); count += 1; } iter.into_remainder().store(1u8); assert_eq!(data, 0b100_010_01); assert_eq!(count, 2);
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).
Panics
Panics if mid > len
.
Examples
let data = 0x0Fu8; let bits = data.bits::<Msb0>(); { let (left, right) = bits.split_at(0); assert!(left.is_empty()); assert_eq!(right, bits); } { let (left, right) = bits.split_at(4); assert!(left.not_any()); assert!(right.all()); } { let (left, right) = bits.split_at(8); assert_eq!(left, bits); assert!(right.is_empty()); }
pub fn split_at_mut(&mut self, mid: usize) -> (&mut Self, &mut Self)
[src]
Divides one mutable slice into two at an index.
The first will contain all indices from [0, mid)
(excluding the index
mid
itself) and the second will contain all indices from [mid, len)
(excluding the index len
itself).
Panics
Panics if mid > len
.
Examples
let mut data = 0x0Fu8; let bits = data.bits_mut::<Msb0>(); let (left, right) = bits.split_at_mut(4); assert!(left.not_any()); assert!(right.all()); *left.at(1) = true; *right.at(2) = false; assert_eq!(data, 0b0100_1101);
pub fn split<F>(&self, func: F) -> Split<'_, O, T, F>ⓘ where
F: FnMut(usize, &bool) -> bool,
[src]
F: FnMut(usize, &bool) -> bool,
Returns an iterator over subslices separated by indexed bits that
satisfy the predicate func
tion. The matched position is not contained
in the subslices.
API Differences
The slice::split
method takes a predicate function with signature
(&T) -> bool
, whereas this method’s predicate function has signature
(usize, &T) -> bool
. This difference is in place because BitSlice
by
definition has only one bit of information per slice item, and including
the index allows the callback function to make more informed choices.
Examples
let data = 0b01_001_000u8; let bits = data.bits::<Msb0>(); let mut iter = bits.split(|pos, bit| *bit); assert_eq!(iter.next().unwrap(), &bits[0 .. 1]); assert_eq!(iter.next().unwrap(), &bits[2 .. 4]); assert_eq!(iter.next().unwrap(), &bits[5 .. 8]); assert!(iter.next().is_none());
If the first position is matched, an empty slice will be the first item returned by the iterator. Similarly, if the last position in the slice is matched, an empty slice will be the last item returned by the iterator:
let data = 1u8; let bits = data.bits::<Msb0>(); let mut iter = bits.split(|pos, bit| *bit); assert_eq!(iter.next().unwrap(), &bits[0 .. 7]); assert_eq!(iter.next().unwrap(), BitSlice::<Local, usize>::empty()); assert!(iter.next().is_none());
If two matched positions are directly adjacent, an empty slice will be present between them.
let data = 0b001_100_00u8; let bits = data.bits::<Msb0>(); let mut iter = bits.split(|pos, bit| *bit); assert_eq!(iter.next().unwrap(), &bits[0 .. 2]); assert_eq!(iter.next().unwrap(), BitSlice::<Local, usize>::empty()); assert_eq!(iter.next().unwrap(), &bits[4 .. 8]); assert!(iter.next().is_none());
pub fn split_mut<F>(&mut self, func: F) -> SplitMut<'_, O, T, F>ⓘ where
F: FnMut(usize, &bool) -> bool,
[src]
F: FnMut(usize, &bool) -> bool,
Returns an iterator over mutable subslices separated by indexed bits
that satisfy the predicate func
tion. The matched position is not
contained in the subslices.
API Differences
The slice::split_mut
method takes a predicate function with
signature (&T) -> bool
, whereas this method’s predicate function has
signature (usize, &T) -> bool
. This difference is in place because
BitSlice
by definition has only one bit of information per slice item,
and including the index allows the callback function to make more
informed choices.
Examples
let mut data = 0b001_000_10u8; let bits = data.bits_mut::<Msb0>(); for group in bits.split_mut(|pos, bit| *bit) { *group.at(0) = true; } assert_eq!(data, 0b101_1001_1u8);
pub fn rsplit<F>(&self, func: F) -> RSplit<'_, O, T, F>ⓘ where
F: FnMut(usize, &bool) -> bool,
[src]
F: FnMut(usize, &bool) -> bool,
Returns an iterator over subslices separated by indexed bits that
satisfy a predicate func
tion, starting at the end of the slice and
working backwards. The matched position is not contained in the
subslices.
API Differences
The slice::rsplit
method takes a predicate function with
signature (&T) -> bool
, whereas this method’s predicate function has
signature (usize, &T) -> bool
. This difference is in place because
BitSlice
by definition has only one bit of information per slice item,
and including the index allows the callback function to make more
informed choices.
Examples
let data = 0b0001_0000u8; let bits = data.bits::<Msb0>(); let mut iter = bits.rsplit(|pos, bit| *bit); assert_eq!(iter.next().unwrap(), &bits[4 .. 8]); assert_eq!(iter.next().unwrap(), &bits[0 .. 3]); assert!(iter.next().is_none());
As with split()
, if the first or last position is matched, an empty
slice will be the first (or last) item returned by the iterator.
let data = 0b1001_0001u8; let bits = data.bits::<Msb0>(); let mut iter = bits.rsplit(|pos, bit| *bit); assert!(iter.next().unwrap().is_empty()); assert_eq!(iter.next().unwrap(), &bits[4 .. 7]); assert_eq!(iter.next().unwrap(), &bits[1 .. 3]); assert!(iter.next().unwrap().is_empty()); assert!(iter.next().is_none());
pub fn rsplit_mut<F>(&mut self, func: F) -> RSplitMut<'_, O, T, F>ⓘ where
F: FnMut(usize, &bool) -> bool,
[src]
F: FnMut(usize, &bool) -> bool,
Returns an iterator over mutable subslices separated by indexed bits
that satisfy a predicate func
tion, starting at the end of the slice
and working backwards. The matched position is not contained in the
subslices.
API Differences
The slice::rsplit_mut
method takes a predicate function with
signature (&T) -> bool
, whereas this method’s predicate function has
signature (usize, &T) -> bool
. This difference is in place because
BitSlice
by definition has only one bit of information per slice item,
and including the index allows the callback function to make more
informed choices.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Msb0>(); let mut count = 0u8; for group in bits.rsplit_mut(|pos, bit| pos % 3 == 2) { count += 1; group.store(count); } assert_eq!(data, 0b11_0_10_0_01);
pub fn splitn<F>(&self, n: usize, func: F) -> SplitN<'_, O, T, F>ⓘ where
F: FnMut(usize, &bool) -> bool,
[src]
F: FnMut(usize, &bool) -> bool,
Returns an iterator over subslices separated by indexed bits that
satisfy the predicate func
tion, limited to returning at most n
items. The matched position is not contained in the subslices.
The last element returned, if any, will contain the remainder of the slice.
API Differences
The slice::splitn
method takes a predicate function with
signature (&T) -> bool
, whereas this method’s predicate function has
signature (usize, &T) -> bool
. This difference is in place because
BitSlice
by definition has only one bit of information per slice item,
and including the index allows the callback function to make more
informed choices.
Examples
Print the slice split once by indices divisible by 3:
let data = 0xA5u8; let bits = data.bits::<Msb0>(); for group in bits.splitn(2, |pos, bit| pos % 3 == 2) { println!("{}", group); } // [10] // [00101]
pub fn splitn_mut<F>(&mut self, n: usize, func: F) -> SplitNMut<'_, O, T, F>ⓘ where
F: FnMut(usize, &bool) -> bool,
[src]
F: FnMut(usize, &bool) -> bool,
Returns an iterator over mutable subslices separated by indexed bits
that satisfy the predicate func
tion, limited to returning at most n
items. The matched position is not contained in the subslices.
The last element returned, if any, will contain the remainder of the slice.
API Differences
The slice::splitn_mut
method takes a predicate function with
signature (&T) -> bool
, whereas this method’s predicate function has
signature (usize, &T) -> bool
. This difference is in place because
BitSlice
by definition has only one bit of information per slice item,
and including the index allows the callback function to make more
informed choices.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Msb0>(); let mut counter = 0u8; for group in bits.splitn_mut(2, |pos, bit| pos % 4 == 3) { counter += 1; group.store(counter); } assert_eq!(data, 0b001_0_0010);
pub fn rsplitn<F>(&self, n: usize, func: F) -> RSplitN<'_, O, T, F>ⓘ where
F: FnMut(usize, &bool) -> bool,
[src]
F: FnMut(usize, &bool) -> bool,
Returns an iterator over subslices separated by indexed bits that
satisfy a predicate func
tion, limited to returning at most n
items.
This starts at the end of the slice and works backwards. The matched
position is not contained in the subslices.
The last element returned, if any, will contain the remainder of the slice.
API Differences
The slice::rsplitn
method takes a predicate function with
signature (&T) -> bool
, whereas this method’s predicate function has
signature (usize, &T) -> bool
. This difference is in place because
BitSlice
by definition has only one bit of information per slice item,
and including the index allows the callback function to make more
informed choices.
Examples
Print the slice split once, starting from the end, by indices divisible by 3:
let data = 0xA5u8; let bits = data.bits::<Msb0>(); for group in bits.rsplitn(2, |pos, bit| pos % 3 == 2) { println!("{}", group); } // [01] // [10100]
pub fn rsplitn_mut<F>(&mut self, n: usize, func: F) -> RSplitNMut<'_, O, T, F>ⓘ where
F: FnMut(usize, &bool) -> bool,
[src]
F: FnMut(usize, &bool) -> bool,
Returns an iterator over mutable subslices separated by indexed bits
that satisfy a predicate func
tion, limited to returning at most n
items. This starts at the end of the slice and works backwards. The
matched position is not contained in the subslices.
The last element returned, if any, will contain the remainder of the slice.
API Differences
The slice::rsplitn_mut
method takes a predicate function with
signature (&T) -> bool
, whereas this method’s predicate function has
signature (usize, &T) -> bool
. This difference is in place because
BitSlice
by definition has only one bit of information per slice item,
and including the index allows the callback function to make more
informed choices.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Msb0>(); let mut counter = 0u8; for group in bits.rsplitn_mut(2, |pos, bit| pos % 3 == 2) { counter += 1; group.store(counter); } assert_eq!(data, 0b00010_0_01);
pub fn contains<P, U>(&self, query: &BitSlice<P, U>) -> bool where
P: BitOrder,
U: BitStore,
[src]
P: BitOrder,
U: BitStore,
Returns true
if the slice contains a region that matches the given
span.
API Differences
The slice::contains
method tests for a single slice element.
Because this is a slice of single bits, testing for the presence of one
bool
value is not very informative. This instead searches for a
subslice, which may be one or more bits.
Examples
let data = 0b0101_1010u8; let bits_be = data.bits::<Msb0>(); let bits_le = data.bits::<Lsb0>(); assert!(bits_be.contains(&bits_le[1 .. 5]));
This example uses a palindrome pattern to demonstrate that the query does not need to have the same type parameters as the searched slice.
pub fn starts_with<P, U>(&self, prefix: &BitSlice<P, U>) -> bool where
P: BitOrder,
U: BitStore,
[src]
P: BitOrder,
U: BitStore,
Returns true
if prefix
is a prefix of the slice.
Examples
let data = 0b0110_1110u8; let bits = data.bits::<Msb0>(); assert!(bits.starts_with(&data.bits::<Lsb0>()[.. 2]));
pub fn ends_with<P, U>(&self, suffix: &BitSlice<P, U>) -> bool where
P: BitOrder,
U: BitStore,
[src]
P: BitOrder,
U: BitStore,
Returns true
if suffix
is a suffix of the slice.
Examples
let data = 0b0111_1010u8; let bits = data.bits::<Msb0>(); assert!(bits.ends_with(&data.bits::<Lsb0>()[6 ..]));
pub fn rotate_left(&mut self, by: usize)
[src]
Rotates the slice in-place such that the first by
bits of the slice
move to the end while the last self.len() - by
bits move to the
front. After calling rotate_left
, the bit previously at index by
will become the first bit in the slice.
Panics
This function will panic if by
is greater than the length of the
slice. Note that by == self.len()
does not panic and is a noöp
rotation.
Complexity
Takes linear (in self.len()
) time.
Examples
let mut data = 0xF0u8; let bits = data.bits_mut::<Msb0>(); bits.rotate_left(2); assert_eq!(data, 0xC3);
Rotating a subslice:
let mut data = 0xF0u8; let bits = data.bits_mut::<Msb0>(); bits[1 .. 5].rotate_left(1); assert_eq!(data, 0b1_1101_000);
pub fn rotate_right(&mut self, by: usize)
[src]
Rotates the slice in-place such that the first self.len() - by
bits of
the slice move to the end while the last by
bits move to the front.
After calling rotate_right
, the bit previously at index
self.len() - by
will become the first bit in the slice.
Panics
This function will panic if by
is greater than the length of the
slice. Note that by == self.len()
does not panic and is a noöp
rotation.
Complexity
Takes linear (in self.len()
) time.
Examples
let mut data = 0xF0u8; let bits = data.bits_mut::<Msb0>(); bits.rotate_right(2); assert_eq!(data, 0x3C);
Rotate a subslice:
let mut data = 0xF0u8; let bits = data.bits_mut::<Msb0>(); bits[1 .. 5].rotate_right(1); assert_eq!(data, 0b1_0111_000);
pub fn clone_from_slice<P, U>(&mut self, src: &BitSlice<P, U>) where
P: BitOrder,
U: BitStore,
[src]
P: BitOrder,
U: BitStore,
Copies the elements from src
into self
.
The length of src
must be the same as self
.
This is equivalent to copy_from_slice
; this function is only included
for API surface equivalence.
Panics
This function will panic if the two slices have different lengths.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Msb0>(); let src = 0x0Fu16.bits::<Lsb0>(); bits.clone_from_slice(&src[.. 8]); assert_eq!(data, 0xF0);
Rust enforces that there can only be one mutable reference with no
immutable references to a particular piece of data in a particular
scope. Because of this, attempting to use clone_from_slice
on a single
slice will result in a compile failure:
let mut data = 3u8; let bits = data.bits_mut::<Msb0>(); bits[.. 2].clone_from_slice(&bits[6 ..]);
To work around this, we can use [split_at_mut
] to create two distinct
sub-slices from a slice:
let mut data = 3u8; let bits = data.bits_mut::<Msb0>(); let (head, tail) = bits.split_at_mut(4); head.clone_from_slice(tail); assert_eq!(data, 0x33);
pub fn copy_from_slice(&mut self, src: &Self)
[src]
Copies the elements from src
into self
.
The length of src
must be the same as self
.
This is restricted to take exactly the same type of bit slice as the
source slice, so that the implementation has the chace to use faster
memcpy
if possible.
Panics
This function will panic if the two slices have different lengths.
Examples
let mut data = 0u8; let bits = data.bits_mut::<Msb0>(); let src = 0x0Fu8.bits::<Msb0>(); bits.copy_from_slice(src); assert_eq!(data, 0x0F);
Rust enforces that there can only be one mutable reference with no
immutable references to a particular piece of data in a particular
scope. Because of this, attempting to use copy_from_slice
on a single
slice will result in a compile failure:
let mut data = 3u8; let bits = data.bits_mut::<Msb0>(); bits[.. 2].copy_from_slice(&bits[6 ..]);
To work around this, we can use [split_at_mut
] to create two distinct
sub-slices from a slice:
let mut data = 3u8; let bits = data.bits_mut::<Msb0>(); let (head, tail) = bits.split_at_mut(4); head.copy_from_slice(tail); assert_eq!(data, 0x33);
pub fn swap_with_slice<P, U>(&mut self, other: &mut BitSlice<P, U>) where
P: BitOrder,
U: BitStore,
[src]
P: BitOrder,
U: BitStore,
Swaps all bits in self
with those in other
.
The length of other
must be the same as self
.
Panics
This function will panic if the two slices hav different lengths.
Example
Swapping two elements across slices:
let mut a = 0u8; let mut b = 0x96A5u16; let bits_a = a.bits_mut::<Lsb0>(); let bits_b = b.bits_mut::<Msb0>(); bits_a.swap_with_slice(&mut bits_b[4 .. 12]); assert_eq!(a, 0x56); assert_eq!(b, 0x9005);
Rust enforces that there can only be one mutable reference to a
particular piece of data in a particular scope. Because of this,
attempting to use swap_with_slice
on a single slice will result in a
compile failure:
let mut data = 15u8; let bits = data.bits_mut::<Msb0>(); bits[.. 3].swap_with_slice(&mut bits[5 ..]);
To work around this, we can use [split_at_mut
] to create two distinct
mutable sub-slices from a slice:
let mut data = 15u8; let bits = data.bits_mut::<Msb0>(); { let (left, right) = bits.split_at_mut(4); left[.. 2].swap_with_slice(&mut right[2 ..]); } assert_eq!(data, 0xCC);
pub unsafe fn align_to<U>(&self) -> (&Self, &BitSlice<O, U>, &Self) where
U: BitStore,
[src]
U: BitStore,
Transmute the slice to a slice with a different backing store, ensuring alignment of the types is maintained.
This method splits the slice into three distinct slices: prefix, correctly aligned middle slice of a new backing type, and the suffix slice. The method does a best effort to make the middle slice the greatest length possible for a given type and input slice, but only your algorithm’s performance should depend on that, not its correctness.
Safety
This method is essentially a transmute
with respect to the elements in
the returned middle slice, so all the usual caveats pertaining to
transmute::<T, U>
also apply here.
Examples
Basic usage:
unsafe { let bytes: [u8; 7] = [1, 2, 3, 4, 5, 6, 7]; let bits = bytes.bits::<Local>(); let (prefix, shorts, suffix) = bits.align_to::<u16>(); match prefix.len() { 0 => { assert_eq!(shorts, bits[.. 48]); assert_eq!(suffix, bits[48 ..]); }, 8 => { assert_eq!(prefix, bits[.. 8]); assert_eq!(shorts, bits[8 ..]); }, _ => unreachable!("This case will not occur") } }
pub unsafe fn align_to_mut<U>(
&mut self
) -> (&mut Self, &mut BitSlice<O, U>, &mut Self) where
U: BitStore,
[src]
&mut self
) -> (&mut Self, &mut BitSlice<O, U>, &mut Self) where
U: BitStore,
Transmute the slice to a slice with a different backing store, ensuring alignment of the types is maintained.
This method splits the slice into three distinct slices: prefix, correctly aligned middle slice of a new backing type, and the suffix slice. The method does a best effort to make the middle slice the greatest length possible for a given type and input slice, but only your algorithm’s performance should depend on that, not its correctness.
Safety
This method is essentially a transmute
with respect to the elements in
the returned middle slice, so all the usual caveats pertaining to
transmute::<T, U>
also apply here.
Examples
Basic usage:
unsafe { let mut bytes: [u8; 7] = [1, 2, 3, 4, 5, 6, 7]; let bits = bytes.bits_mut::<Local>(); let (prefix, shorts, suffix) = bits.align_to_mut::<u16>(); // same access and behavior as in `align_to` }
pub fn to_vec(&self) -> BitVec<O, T>
[src]
Copies self
into a new BitVec
.
Examples
let data = [0u8, !0u8]; let bits = data.bits::<Local>(); let vec = bits.to_vec(); assert_eq!(bits, vec);
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 domain0 .. self.len()
.value
: The value to be set,true
for1
andfalse
for0
.
Panics
This method panics if index
is outside the slice domain.
Examples
use bitvec::prelude::*; let mut store = 8u8; let bits = store.bits_mut::<Msb0>(); 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 ofself
.
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.bits_mut::<Msb0>()[2 .. 4]; assert_eq!(bits.len(), 2); unsafe { bits.set_unchecked(5, true); } } assert_eq!(src, 1);
pub fn at<'a, I>(&'a mut self, index: I) -> I::Mut where
I: BitSliceIndex<'a, O, T>,
[src]
I: BitSliceIndex<'a, O, T>,
Use .get_mut()
instead
Produces a write reference to a region of the slice.
This method corresponds to [Index::index
], except that it produces a
writable reference rather than a read-only reference. See
BitSliceIndex
for the possible types of the produced reference.
Use of this method locks the &mut BitSlice
for the duration of the
produced reference’s lifetime. If you need multiple non-overlapping
write references into a single source &mut BitSlice
, see the
::split_at_mut
method.
Lifetimes
'a
: Propagates the lifetime of the referent slice to the interior reference produced.
Parameters
&mut self
index
: Some value whose type can be used to indexBitSlice
s.
Returns
A writable reference into self
, whose exact type is determined by
index
’s implementation of BitSliceIndex
. This may be either a
smaller &mut BitSlice
when index
is a range, or a BitMut
proxy
type when index
is a usize
. See the BitMut
documentation for
information on how to use it.
Panics
This panics if index
is out of bounds of self
.
Examples
use bitvec::prelude::*; let mut src = 0u8; let bits = src.bits_mut::<Msb0>(); 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.bits_mut::<Msb0>(); { 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 unsafe fn at_unchecked<'a, I>(&'a mut self, index: I) -> I::Mut where
I: BitSliceIndex<'a, O, T>,
[src]
I: BitSliceIndex<'a, O, T>,
Use .get_unchecked_mut()
instead
Version of at
that does not perform boundary checking.
Safety
If index
is outside the boundaries of self
, then this function will
induce safety violations. The caller must ensure that index
is within
the boundaries of self
before calling.
pub unsafe fn split_at_unchecked(&self, mid: usize) -> (&Self, &Self)
[src]
Version of split_at
that does not perform boundary
checking.
Safety
If mid
is outside the boundaries of self
, then this function will
induce safety violations. The caller must ensure that mid
is within
the boundaries of self
before calling.
pub unsafe fn split_at_mut_unchecked(
&mut self,
mid: usize
) -> (&mut Self, &mut Self)
[src]
&mut self,
mid: usize
) -> (&mut Self, &mut Self)
Version of split_at_mut
that does not perform
boundary checking.
Safety
If mid
is outside the boundaries of self
, then this function will
induce safety violations. The caller must ensure that mid
is within
the boundaries of self
before calling.
pub unsafe fn swap_unchecked(&mut self, a: usize, b: usize)
[src]
Version of swap
that does not perform boundary checks.
Safety
a
and b
must be within the bounds of self
, otherwise, the memory
access is unsound and may induce undefined behavior.
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.bits::<Msb0>(); assert!(bits[.. 4].all()); assert!(!bits[4 ..].all());
pub fn any(&self) -> bool
[src]
Tests if any bit in the slice is set (logical ∨
).
Truth Table
0 0 => 0
0 1 => 1
1 0 => 1
1 1 => 1
Parameters
&self
Returns
Whether any bit in the slice domain is set. The empty slice returns
false
.
Examples
use bitvec::prelude::*; let bits = 0x40u8.bits::<Msb0>(); assert!(bits[.. 4].any()); assert!(!bits[4 ..].any());
pub fn not_all(&self) -> bool
[src]
Tests if any bit in the slice is unset (logical ¬∧
).
Truth Table
0 0 => 1
0 1 => 1
1 0 => 1
1 1 => 0
Parameters
- `&self
Returns
Whether any bit in the slice domain is unset.
Examples
use bitvec::prelude::*; let bits = 0xFDu8.bits::<Msb0>(); assert!(!bits[.. 4].not_all()); assert!(bits[4 ..].not_all());
pub fn not_any(&self) -> bool
[src]
Tests if all bits in the slice are unset (logical ¬∨
).
Truth Table
0 0 => 1
0 1 => 0
1 0 => 0
1 1 => 0
Parameters
&self
Returns
Whether all bits in the slice domain are unset.
Examples
use bitvec::prelude::*; let bits = 0x40u8.bits::<Msb0>(); assert!(!bits[.. 4].not_any()); assert!(bits[4 ..].not_any());
pub fn some(&self) -> bool
[src]
Tests whether the slice has some, but not all, bits set and some, but not all, bits unset.
This is false
if either all()
or not_any()
are true
.
Truth Table
0 0 => 0
0 1 => 1
1 0 => 1
1 1 => 0
Parameters
&self
Returns
Whether the slice domain has mixed content. The empty slice returns
false
.
Examples
use bitvec::prelude::*; let bits = 0b111_000_10u8.bits::<Msb0>(); 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].bits::<Msb0>(); 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].bits::<Msb0>(); 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.bits_mut::<Msb0>(); 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]
F: Fn(usize, bool) -> bool,
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.bits_mut::<Msb0>(); 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]
I: IntoIterator<Item = bool>,
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
Lsb0
BitOrder
type.
Parameters
&mut self
: The addition usesself
as one addend, and writes the sum back intoself
.addend: impl IntoIterator<Item=bool>
: A stream of bits. When this is anotherBitSlice
, 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.bits_mut::<Lsb0>()[.. 4]; let bb = & b.bits::<Lsb0>()[.. 4]; let c = ab.add_assign_reverse(bb.iter().copied()); assert!(c); assert_eq!(a, 0b0000_0110u8);
Performance Notes
When using Lsb0
BitOrder
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, please file an issue.
pub fn as_slice(&self) -> &[T]
[src]
Accesses the backing storage of the BitSlice
as a slice of its
elements.
This will not include partially-owned edge elements, as they may be contended by other slice handles.
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.bits::<Msb0>(); let accum = bits.as_slice() .iter() .map(|elt| elt.count_ones()) .sum::<u32>(); assert_eq!(accum, 3);
pub fn as_mut_slice(&mut self) -> &mut [T]
[src]
Accesses the underlying store.
This will not include partially-owned edge elements, as they may be contended by other slice handles.
Examples
use bitvec::prelude::*; let mut src = [1u8, 64]; let bits = src.bits_mut::<Msb0>(); for elt in bits.as_mut_slice() { *elt |= 2; } assert_eq!(&[3, 66], bits.as_slice());
pub fn as_total_slice(&self) -> &[T::Access]
[src]
Accesses the underlying store, including contended partial elements.
This produces a slice of element wrappers that permit shared mutation,
rather than a slice of the bare T
fundamentals.
Parameters
&self
Returns
A slice of all elements under the bit span, including any partially-owned edge elements, wrapped in safe shared-mutation types.
Trait Implementations
impl<O, T> Add<BitBox<O, T>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Output = Self
The resulting type after applying the +
operator.
fn add(self, addend: Self) -> Self::Output
[src]
impl<O, T> AddAssign<BitBox<O, T>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
fn add_assign(&mut self, addend: Self)
[src]
impl<O, T> AsMut<[T]> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> AsMut<BitSlice<O, T>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> AsRef<[T]> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> AsRef<BitSlice<O, T>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> Binary for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T, I> BitAnd<I> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
[src]
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
type Output = Self
The resulting type after applying the &
operator.
fn bitand(self, rhs: I) -> Self::Output
[src]
impl<O, T, I> BitAndAssign<I> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
[src]
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
fn bitand_assign(&mut self, rhs: I)
[src]
impl<O, T> BitField for BitBox<O, T> where
O: BitOrder,
T: BitStore,
BitSlice<O, T>: BitField,
[src]
O: BitOrder,
T: BitStore,
BitSlice<O, T>: BitField,
fn load_le<U>(&self) -> U where
U: BitStore,
[src]
U: BitStore,
fn load_be<U>(&self) -> U where
U: BitStore,
[src]
U: BitStore,
fn store_le<U>(&mut self, value: U) where
U: BitStore,
[src]
U: BitStore,
fn store_be<U>(&mut self, value: U) where
U: BitStore,
[src]
U: BitStore,
fn load<U>(&self) -> U where
U: BitStore,
[src]
U: BitStore,
fn store<U>(&mut self, value: U) where
U: BitStore,
[src]
U: BitStore,
impl<O, T, I> BitOr<I> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
[src]
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
type Output = Self
The resulting type after applying the |
operator.
fn bitor(self, rhs: I) -> Self::Output
[src]
impl<O, T, I> BitOrAssign<I> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
[src]
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
fn bitor_assign(&mut self, rhs: I)
[src]
impl<O, T, I> BitXor<I> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
[src]
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
type Output = Self
The resulting type after applying the ^
operator.
fn bitxor(self, rhs: I) -> Self::Output
[src]
impl<O, T, I> BitXorAssign<I> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
[src]
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
fn bitxor_assign(&mut self, rhs: I)
[src]
impl<O, T> Borrow<BitSlice<O, T>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> BorrowMut<BitSlice<O, T>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
fn borrow_mut(&mut self) -> &mut BitSlice<O, T>
[src]
impl<O, T> Clone for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<O, T> Debug for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> Default for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> Deref for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Target = BitSlice<O, T>
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
impl<O, T> DerefMut for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> Display for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> Drop for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> Eq for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> From<&'_ [T]> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> From<&'_ BitSlice<O, T>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> From<BitBox<O, T>> for BitVec<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> From<BitVec<O, T>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> From<Box<[T], Global>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> Hash for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
fn hash<H: Hasher>(&self, hasher: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<O, T> Index<Range<usize>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Output = BitSlice<O, T>
The returned type after indexing.
fn index(&self, range: Range<usize>) -> &Self::Output
[src]
impl<O, T> Index<RangeFrom<usize>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Output = BitSlice<O, T>
The returned type after indexing.
fn index(&self, range: RangeFrom<usize>) -> &Self::Output
[src]
impl<O, T> Index<RangeFull> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Output = BitSlice<O, T>
The returned type after indexing.
fn index(&self, _: RangeFull) -> &Self::Output
[src]
impl<O, T> Index<RangeInclusive<usize>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Output = BitSlice<O, T>
The returned type after indexing.
fn index(&self, range: RangeInclusive<usize>) -> &Self::Output
[src]
impl<O, T> Index<RangeTo<usize>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Output = BitSlice<O, T>
The returned type after indexing.
fn index(&self, range: RangeTo<usize>) -> &Self::Output
[src]
impl<O, T> Index<RangeToInclusive<usize>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Output = BitSlice<O, T>
The returned type after indexing.
fn index(&self, range: RangeToInclusive<usize>) -> &Self::Output
[src]
impl<O, T> Index<usize> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Output = bool
The returned type after indexing.
fn index(&self, index: usize) -> &Self::Output
[src]
impl<O, T> IndexMut<Range<usize>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> IndexMut<RangeFrom<usize>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> IndexMut<RangeFull> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> IndexMut<RangeInclusive<usize>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
fn index_mut(&mut self, range: RangeInclusive<usize>) -> &mut Self::Output
[src]
impl<O, T> IndexMut<RangeTo<usize>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> IndexMut<RangeToInclusive<usize>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
fn index_mut(&mut self, range: RangeToInclusive<usize>) -> &mut Self::Output
[src]
impl<O, T> Into<Box<[T], Global>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> IntoIterator for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Item = bool
The type of the elements being iterated over.
type IntoIter = IntoIter<O, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, O, T> IntoIterator for &'a BitBox<O, T> where
O: BitOrder,
T: 'a + BitStore,
[src]
O: BitOrder,
T: 'a + BitStore,
type Item = &'a bool
The type of the elements being iterated over.
type IntoIter = <&'a BitSlice<O, T> as IntoIterator>::IntoIter
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, O, T> IntoIterator for &'a mut BitBox<O, T> where
O: BitOrder,
T: 'a + BitStore,
[src]
O: BitOrder,
T: 'a + BitStore,
type Item = BitMut<'a, O, T>
The type of the elements being iterated over.
type IntoIter = <&'a mut BitSlice<O, T> as IntoIterator>::IntoIter
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<O, T> LowerHex for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> Neg for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Output = Self
The resulting type after applying the -
operator.
fn neg(self) -> Self::Output
[src]
impl<O, T> Not for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Output = Self
The resulting type after applying the !
operator.
fn not(self) -> Self::Output
[src]
impl<O, T> Octal for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
impl<O, T> Ord for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
fn cmp(&self, rhs: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<A, B, C, D> PartialEq<BitBox<C, D>> for BitBox<A, B> where
A: BitOrder,
B: BitStore,
C: BitOrder,
D: BitStore,
[src]
A: BitOrder,
B: BitStore,
C: BitOrder,
D: BitStore,
fn eq(&self, rhs: &BitBox<C, D>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A, B, C, D> PartialEq<BitBox<C, D>> for BitSlice<A, B> where
A: BitOrder,
B: BitStore,
C: BitOrder,
D: BitStore,
[src]
A: BitOrder,
B: BitStore,
C: BitOrder,
D: BitStore,
fn eq(&self, rhs: &BitBox<C, D>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A, B, C, D> PartialEq<BitSlice<C, D>> for BitBox<A, B> where
A: BitOrder,
B: BitStore,
C: BitOrder,
D: BitStore,
[src]
A: BitOrder,
B: BitStore,
C: BitOrder,
D: BitStore,
fn eq(&self, rhs: &BitSlice<C, D>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A, B, C, D> PartialOrd<BitBox<C, D>> for BitBox<A, B> where
A: BitOrder,
B: BitStore,
C: BitOrder,
D: BitStore,
[src]
A: BitOrder,
B: BitStore,
C: BitOrder,
D: BitStore,
fn partial_cmp(&self, rhs: &BitBox<C, D>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A, B, C, D> PartialOrd<BitBox<C, D>> for BitSlice<A, B> where
A: BitOrder,
B: BitStore,
C: BitOrder,
D: BitStore,
[src]
A: BitOrder,
B: BitStore,
C: BitOrder,
D: BitStore,
fn partial_cmp(&self, rhs: &BitBox<C, D>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A, B, C, D> PartialOrd<BitSlice<C, D>> for BitBox<A, B> where
A: BitOrder,
B: BitStore,
C: BitOrder,
D: BitStore,
[src]
A: BitOrder,
B: BitStore,
C: BitOrder,
D: BitStore,
fn partial_cmp(&self, rhs: &BitSlice<C, D>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<O, T> Send for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
BitBox
is safe to move across thread boundaries, as is &mut BitBox
.
impl<O, T> Shl<usize> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Output = Self
The resulting type after applying the <<
operator.
fn shl(self, shamt: usize) -> Self::Output
[src]
impl<O, T> ShlAssign<usize> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
fn shl_assign(&mut self, shamt: usize)
[src]
impl<O, T> Shr<usize> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
type Output = Self
The resulting type after applying the >>
operator.
fn shr(self, shamt: usize) -> Self::Output
[src]
impl<O, T> ShrAssign<usize> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
fn shr_assign(&mut self, shamt: usize)
[src]
impl<O, T> Sync for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
&BitBox
is safe to move across thread boundaries.
impl<O, T> UpperHex for BitBox<O, T> where
O: BitOrder,
T: BitStore,
[src]
O: BitOrder,
T: BitStore,
Auto Trait Implementations
impl<O, T> RefUnwindSafe for BitBox<O, T> where
O: RefUnwindSafe,
T: RefUnwindSafe,
O: RefUnwindSafe,
T: RefUnwindSafe,
impl<O, T> Unpin for BitBox<O, T> where
O: Unpin,
T: Unpin,
O: Unpin,
T: Unpin,
impl<O, T> UnwindSafe for BitBox<O, T> where
O: UnwindSafe,
T: UnwindSafe,
O: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,