#[repr(C, align(8))]pub struct BitRef<'a, M = Const, T = usize, O = Lsb0>{ /* private fields */ }Expand description
Proxy Bit-Reference
This structure simulates &/mut bool within BitSlice regions. It is analogous
to the C++ type std::bitset<N>::reference.
This type wraps a BitPtr and caches a bool in one of the remaining padding
bytes. It is then able to freely give out references to its cached bool, and
commits the cached value back to the proxied location when dropped.
Original
This is semantically equivalent to &'a bool or &'a mut bool.
Quirks
Because this type has both a lifetime and a destructor, it can introduce an
uncommon syntax error condition in Rust. When an expression that produces this
type is in the final expression of a block, including if that expression is used
as a condition in a match, if let, or if, then the compiler will attempt
to extend the drop scope of this type to the outside of the block. This causes a
lifetime mismatch error if the source region from which this proxy is produced
begins its lifetime inside the block.
If you get a compiler error that this type causes something to be dropped while borrowed, you can end the borrow by putting any expression-ending syntax element after the offending expression that produces this type, including a semicolon or an item definition.
Examples
use bitvec::prelude::*;
let bits = bits![mut 0; 2];
let (left, right) = bits.split_at_mut(1);
let mut first = left.get_mut(0).unwrap();
let second = right.get_mut(0).unwrap();
// Writing through a dereference requires a `mut` binding.
*first = true;
// Writing through the explicit method call does not.
second.commit(true);
drop(first); // It’s not a reference, so NLL does not apply!
assert_eq!(bits, bits![1; 2]);Implementations§
source§impl<M, T, O> BitRef<'_, M, T, O>
 
impl<M, T, O> BitRef<'_, M, T, O>
sourcepub unsafe fn from_bitptr(bitptr: BitPtr<M, T, O>) -> Self
 
pub unsafe fn from_bitptr(bitptr: BitPtr<M, T, O>) -> Self
Converts a bit-pointer into a proxy bit-reference.
This reads through the pointer in order to cache the current bit value in the proxy.
Original
The syntax unsafe { &* ptr }.
Safety
This is equivalent to (and is!) dereferencing a raw pointer. The pointer must be well-constructed, refer to a live memory location in the program context, and not be aliased beyond its typing indicators.
sourcepub fn into_bitptr(self) -> BitPtr<M, T, O>
 
pub fn into_bitptr(self) -> BitPtr<M, T, O>
source§impl<T, O> BitRef<'_, Mut, T, O>
 
impl<T, O> BitRef<'_, Mut, T, O>
Trait Implementations§
source§impl<'a, M, T1, T2, O1, O2> Extend<BitRef<'a, M, T2, O2>> for BitVec<T1, O1>
 
impl<'a, M, T1, T2, O1, O2> Extend<BitRef<'a, M, T2, O2>> for BitVec<T1, O1>
Bit-Vector Extension by Proxy References
DO NOT use this. You clearly have a bit-slice. Use
.extend_from_bitslice() instead!
Iterating over a bit-slice requires loading from memory and constructing a proxy reference for each bit. This is needlessly slow; the specialized method is able to avoid this per-bit cost and possibly even use batched operations.
source§fn extend<I>(&mut self, iter: I)where
    I: IntoIterator<Item = BitRef<'a, M, T2, O2>>,
 
fn extend<I>(&mut self, iter: I)where
    I: IntoIterator<Item = BitRef<'a, M, T2, O2>>,
§fn extend_one(&mut self, item: A)
 
fn extend_one(&mut self, item: A)
extend_one)§fn extend_reserve(&mut self, additional: usize)
 
fn extend_reserve(&mut self, additional: usize)
extend_one)source§impl<'a, M, T1, T2, O1, O2> FromIterator<BitRef<'a, M, T2, O2>> for BitVec<T1, O1>
 
impl<'a, M, T1, T2, O1, O2> FromIterator<BitRef<'a, M, T2, O2>> for BitVec<T1, O1>
Bit-Vector Collection from Proxy References
DO NOT use this. You clearly have a bit-slice. Use
::from_bitslice() instead!
Iterating over a bit-slice requires loading from memory and constructing a proxy reference for each bit. This is needlessly slow; the specialized method is able to avoid this per-bit cost and possibly even use batched operations.
source§impl<M, T, O> Ord for BitRef<'_, M, T, O>
 
impl<M, T, O> Ord for BitRef<'_, M, T, O>
source§impl<M, T, O> PartialEq<BitRef<'_, M, T, O>> for &bool
 
impl<M, T, O> PartialEq<BitRef<'_, M, T, O>> for &bool
source§impl<M, T, O> PartialEq<BitRef<'_, M, T, O>> for bool
 
impl<M, T, O> PartialEq<BitRef<'_, M, T, O>> for bool
source§impl<M1, M2, O1, O2, T1, T2> PartialEq<BitRef<'_, M2, T2, O2>> for BitRef<'_, M1, T1, O1>
 
impl<M1, M2, O1, O2, T1, T2> PartialEq<BitRef<'_, M2, T2, O2>> for BitRef<'_, M1, T1, O1>
source§impl<M, T, O> PartialOrd<&bool> for BitRef<'_, M, T, O>
 
impl<M, T, O> PartialOrd<&bool> for BitRef<'_, M, T, O>
source§impl<M1, M2, O1, O2, T1, T2> PartialOrd<BitRef<'_, M2, T2, O2>> for BitRef<'_, M1, T1, O1>
 
impl<M1, M2, O1, O2, T1, T2> PartialOrd<BitRef<'_, M2, T2, O2>> for BitRef<'_, M1, T1, O1>
source§impl<M, T, O> PartialOrd<bool> for BitRef<'_, M, T, O>
 
impl<M, T, O> PartialOrd<bool> for BitRef<'_, M, T, O>
impl<M, T, O> Eq for BitRef<'_, M, T, O>
impl<M, T, O> Send for BitRef<'_, M, T, O>
impl<M, T, O> Sync for BitRef<'_, M, T, O>
Auto Trait Implementations§
impl<'a, M = Const, T = usize, O = Lsb0> !RefUnwindSafe for BitRef<'a, M, T, O>
impl<'a, M, T, O> Unpin for BitRef<'a, M, T, O>where
    M: Unpin,
    O: Unpin,
impl<'a, M = Const, T = usize, O = Lsb0> !UnwindSafe for BitRef<'a, M, T, O>
Blanket Implementations§
§impl<T> Any for Twhere
    T: 'static + ?Sized,
 
impl<T> Any for Twhere
    T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
    T: ?Sized,
 
impl<T> Borrow<T> for Twhere
    T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
source§impl<T> FmtForward for T
 
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
    Self: Binary,
 
fn fmt_binary(self) -> FmtBinary<Self>where
    Self: Binary,
self to use its Binary implementation when Debug-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
    Self: Display,
 
fn fmt_display(self) -> FmtDisplay<Self>where
    Self: Display,
self to use its Display implementation when
Debug-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
    Self: LowerExp,
 
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
    Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
    Self: LowerHex,
 
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
    Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
    Self: Octal,
 
fn fmt_octal(self) -> FmtOctal<Self>where
    Self: Octal,
self to use its Octal implementation when Debug-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
    Self: Pointer,
 
fn fmt_pointer(self) -> FmtPointer<Self>where
    Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
    Self: UpperExp,
 
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
    Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
    Self: UpperHex,
 
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
    Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§impl<T, U> Into<U> for Twhere
    U: From<T>,
 
impl<T, U> Into<U> for Twhere
    U: From<T>,
source§impl<T> Pipe for Twhere
    T: ?Sized,
 
impl<T> Pipe for Twhere
    T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
    Self: Sized,
 
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
    Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
    R: 'a,
 
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
    R: 'a,
self and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
    R: 'a,
 
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
    R: 'a,
self and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
    Self: Borrow<B>,
    B: 'a + ?Sized,
    R: 'a,
 
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
    Self: Borrow<B>,
    B: 'a + ?Sized,
    R: 'a,
source§fn pipe_borrow_mut<'a, B, R>(
    &'a mut self,
    func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
    Self: BorrowMut<B>,
    B: 'a + ?Sized,
    R: 'a,
 
fn pipe_borrow_mut<'a, B, R>(
    &'a mut self,
    func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
    Self: BorrowMut<B>,
    B: 'a + ?Sized,
    R: 'a,
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
    Self: AsRef<U>,
    U: 'a + ?Sized,
    R: 'a,
 
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
    Self: AsRef<U>,
    U: 'a + ?Sized,
    R: 'a,
self, then passes self.as_ref() into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
    Self: AsMut<U>,
    U: 'a + ?Sized,
    R: 'a,
 
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
    Self: AsMut<U>,
    U: 'a + ?Sized,
    R: 'a,
self, then passes self.as_mut() into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere
    Self: Deref<Target = T>,
    T: 'a + ?Sized,
    R: 'a,
 
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere
    Self: Deref<Target = T>,
    T: 'a + ?Sized,
    R: 'a,
self, then passes self.deref() into the pipe function.source§fn pipe_deref_mut<'a, T, R>(
    &'a mut self,
    func: impl FnOnce(&'a mut T) -> R
) -> Rwhere
    Self: DerefMut<Target = T> + Deref,
    T: 'a + ?Sized,
    R: 'a,
 
fn pipe_deref_mut<'a, T, R>(
    &'a mut self,
    func: impl FnOnce(&'a mut T) -> R
) -> Rwhere
    Self: DerefMut<Target = T> + Deref,
    T: 'a + ?Sized,
    R: 'a,
self, then passes self.deref_mut() into the pipe
function.source§impl<T> Tap for T
 
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
    Self: Borrow<B>,
    B: ?Sized,
 
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
    Self: Borrow<B>,
    B: ?Sized,
Borrow<B> of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
    Self: BorrowMut<B>,
    B: ?Sized,
 
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
    Self: BorrowMut<B>,
    B: ?Sized,
BorrowMut<B> of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
    Self: AsRef<R>,
    R: ?Sized,
 
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
    Self: AsRef<R>,
    R: ?Sized,
AsRef<R> view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
    Self: AsMut<R>,
    R: ?Sized,
 
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
    Self: AsMut<R>,
    R: ?Sized,
AsMut<R> view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
    Self: Deref<Target = T>,
    T: ?Sized,
 
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
    Self: Deref<Target = T>,
    T: ?Sized,
Deref::Target of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
    Self: DerefMut<Target = T> + Deref,
    T: ?Sized,
 
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
    Self: DerefMut<Target = T> + Deref,
    T: ?Sized,
Deref::Target of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
 
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
 
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
    Self: Borrow<B>,
    B: ?Sized,
 
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
    Self: Borrow<B>,
    B: ?Sized,
.tap_borrow() only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
    Self: BorrowMut<B>,
    B: ?Sized,
 
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
    Self: BorrowMut<B>,
    B: ?Sized,
.tap_borrow_mut() only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
    Self: AsRef<R>,
    R: ?Sized,
 
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
    Self: AsRef<R>,
    R: ?Sized,
.tap_ref() only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
    Self: AsMut<R>,
    R: ?Sized,
 
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
    Self: AsMut<R>,
    R: ?Sized,
.tap_ref_mut() only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Selfwhere
    Self: Deref<Target = T>,
    T: ?Sized,
 
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Selfwhere
    Self: Deref<Target = T>,
    T: ?Sized,
.tap_deref() only in debug builds, and is erased in release
builds.source§fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
    Self: DerefMut<Target = T> + Deref,
    T: ?Sized,
 
fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
    Self: DerefMut<Target = T> + Deref,
    T: ?Sized,
.tap_deref_mut() only in debug builds, and is erased in release
builds.