Function bitvec::ptr::write[][src]

pub unsafe fn write<O, T>(dst: BitPtr<Mut, O, T>, value: bool) where
    O: BitOrder,
    T: BitStore

Overwrites a memory location with the given bit.

Because this reads from memory in order to construct the new value, it cannot be used to set uninitialized memory. The referent T element must be fully initialized (such as with core::ptr::write) before setting bits with this function.

Original

ptr::write

Safety

Behavior is undefined if any of the following conditions are violated:

  • dst must be valid for writes
  • dst must point to a properly initialized value of type T
  • no other pointer must race dst to view or modify the referent location unless T is capable of ensuring race safety.

Examples

use bitvec::prelude::*;

let mut data = 0u8;
let ptr = BitPtr::<_, Lsb0, _>::from_mut(&mut data);
unsafe {
  bitvec::ptr::write(ptr.add(2), true);
}
assert_eq!(data, 4);