This writes a new value into a location, and returns the bit-value previously stored there. It is semantically and behaviorally equivalent to BitRef::replace
, except that it works on bit-pointer structures rather than proxy references. Prefer to use a proxy reference or BitSlice::replace
instead.
This has the same safety requirements as ptr::read
and ptr::write
, as it is required to use them in its implementation.
use bitvec::prelude::*; use bitvec::ptr as bv_ptr; let mut data = 4u8; let ptr = BitPtr::<_, _, Lsb0>::from_mut(&mut data); assert!(unsafe { bv_ptr::replace(ptr.add(2), false) }); assert_eq!(data, 0);