File: read_unaligned.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 (30 lines) | stat: -rw-r--r-- 738 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
# Single-Bit Unaligned Read

This reads the bit out of `src` directly. It uses compiler intrinsics to
tolerate an unaligned `T` address. However, because `BitPtr` has a type
invariant that addresses are always well-aligned (and non-null), this has no
benefit or purpose.

## Original

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

## Safety

Because this performs a dereference of memory, it inherits the original
`ptr::read_unaligned`’s requirements:

- `src` must be valid to read.
- `src` must point to an initialized value of `T`.

## Examples

```rust
use bitvec::prelude::*;
use bitvec::ptr as bv_ptr;


let data = 128u8;
let ptr = BitPtr::<_, _, Msb0>::from_ref(&data);
assert!(unsafe { bv_ptr::read_unaligned(ptr) });
```