[][src]Struct bitvec::slice::BitMut

pub struct BitMut<'a, O, T> where
    O: BitOrder,
    T: 'a + BitStore
{ /* fields omitted */ }

Proxy reference type, equivalent to &mut bool.

This is a two-word structure capable of correctly referring to a single bit in a memory element. Because Rust does not permit reference-like objects in the same manner that C++ does – &T and &mut T values are required to be immediately-valid pointers, not objects – bitvec cannot manifest encoded &mut Bit values in the same way that it can manifest &mut BitSlice.

Instead, this type implements Deref and DerefMut to an internal bool slot, and in Drop commits the value of that bool to the proxied bit in the source BitSlice from which the BitMut value was created. The combination of Rust’s own exclusion rules and the aliasing type system in this library ensure that a BitMut value has unique access to the bit it proxies, and the memory element it uses will not have destructive data races from other views.

Lifetimes

  • 'a: The lifetime of the source &'a mut BitSlice that created the BitMut.

Type Parameters

  • O: The BitOrder type parameter from the source &mut BitSlice.
  • T: The BitStore type parameter from the source &mut BitSlice.

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();

// Referential behavior
*first = true;
// Direct write
second.set(true);

drop(first); // it’s not a reference!
assert_eq!(bits, bits![1; 2]);

Implementations

impl<O, T, '_> BitMut<'_, O, T> where
    O: BitOrder,
    T: BitStore
[src]

pub fn set(self, value: bool)[src]

Writes a bit into the proxied location without an intermediate copy.

This function writes value directly into the proxied location, and does not store value in the proxy’s internal cache. This should be equivalent to the behavior seen when using ordinary DerefMut proxying, but the latter depends on compiler optimization.

Parameters

  • self: This destroys the proxy, as it becomes invalid when writing directly to the location without updating the cache.
  • value: The new bit to write into the proxied slot.

Trait Implementations

impl<O, T, '_> Debug for BitMut<'_, O, T> where
    O: BitOrder,
    T: BitStore
[src]

impl<O, T, '_> Deref for BitMut<'_, O, T> where
    O: BitOrder,
    T: BitStore
[src]

type Target = bool

The resulting type after dereferencing.

impl<O, T, '_> DerefMut for BitMut<'_, O, T> where
    O: BitOrder,
    T: BitStore
[src]

impl<O, T, '_> Drop for BitMut<'_, O, T> where
    O: BitOrder,
    T: BitStore
[src]

Auto Trait Implementations

impl<'a, O, T> RefUnwindSafe for BitMut<'a, O, T> where
    O: RefUnwindSafe,
    T: RefUnwindSafe,
    <T as BitStore>::Access: RefUnwindSafe,
    <T as BitStore>::Mem: RefUnwindSafe

impl<'a, O, T> !Send for BitMut<'a, O, T>

impl<'a, O, T> !Sync for BitMut<'a, O, T>

impl<'a, O, T> Unpin for BitMut<'a, O, T> where
    <T as BitStore>::Mem: Unpin

impl<'a, O, T> !UnwindSafe for BitMut<'a, O, T>

Blanket Implementations

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

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

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

impl<T> Conv for T[src]

impl<T> Conv for T[src]

impl<T> FmtForward for T[src]

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

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

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

impl<T> Pipe for T[src]

impl<T> PipeAsRef for T[src]

impl<T> PipeBorrow for T[src]

impl<T> PipeDeref for T[src]

impl<T> PipeRef for T[src]

impl<T> Tap for T[src]

impl<T> Tap for T[src]

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

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

impl<T> TapDeref for T[src]

impl<T> TryConv for T[src]

impl<T> TryConv for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.