File: replace.md

package info (click to toggle)
rust-coreutils 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 505,620 kB
  • sloc: ansic: 103,594; asm: 28,570; sh: 8,910; python: 5,581; makefile: 472; cpp: 97; javascript: 72
file content (35 lines) | stat: -rw-r--r-- 881 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Single-Bit Replacement

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`][0], except that it works on bit-pointer structures rather
than proxy references. Prefer to use a proxy reference or
[`BitSlice::replace`][1] instead.

## Original

[`ptr::replace`](core::ptr::replace)

## Safety

This has the same safety requirements as [`ptr::read`][2] and [`ptr::write`][3],
as it is required to use them in its implementation.

## Examples

```rust
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);
```

[0]: crate::ptr::BitRef::replace
[1]: crate::slice::BitSlice::replace
[2]: crate::ptr::read
[3]: crate::ptr::write