File: eq.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 (38 lines) | stat: -rw-r--r-- 1,059 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
36
37
38
# Bit-Pointer Equality

This compares two bit-pointers for equality by their address value, not by the
value of their referent bit. This does not dereference either.

## Original

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

## API Differences

The two bit-pointers can differ in their storage type parameters. `bitvec`
defines pointer equality only between pointers with the same underlying
[`BitStore::Mem`][0] element type. Numerically-equal bit-pointers with different
integer types *will not* compare equal, though this function will compile and
accept them.

This cannot compare encoded span poiters. `*const BitSlice` can be used in the
standard-library `ptr::eq`, and does not need an override.

## Examples

```rust
use bitvec::prelude::*;
use bitvec::ptr as bv_ptr;
use core::cell::Cell;

let data = 0u16;
let bare_ptr = BitPtr::<_, _, Lsb0>::from_ref(&data);
let cell_ptr = bare_ptr.cast::<Cell<u16>>();

assert!(bv_ptr::eq(bare_ptr, cell_ptr));

let byte_ptr = bare_ptr.cast::<u8>();
assert!(!bv_ptr::eq(bare_ptr, byte_ptr));
```

[0]: crate::store::BitStore::Mem