Skip to content

Commit 6fa4c04

Browse files
authored
Update src/expressions/operator-expr.md
1 parent cba1a9f commit 6fa4c04

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/expressions/operator-expr.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,18 @@ Casts to the `char` with the corresponding code point.
401401
Casting from a pointer to unsized type to pointer to sized type discards the pointer metadata, resulting in just a pointer to the referenced memory.
402402
Casting between pointers to unsized type preserves the pointer metadata unchanged (e.g. the slice element length remains the same).
403403

404+
To illustrate:
405+
406+
```rust
407+
let u8_slice_ptr = ptr::slice_from_raw_parts::<u8>(ptr::null(), 4);
408+
assert_eq!((ptr::null(), 4), u8_slice_ptr.to_raw_parts());
409+
410+
let u8_ptr = u8_slice_ptr as *const u8;
411+
assert_eq!((ptr::null(), ()), u8_ptr.to_raw_parts());
412+
413+
let u16_slice_ptr = u8_slice_ptr as *const [u16];
414+
assert_eq!((ptr::null(), 4), u16_slice_ptr.to_raw_parts());
415+
```
404416
#### Pointer to address cast
405417

406418
Casting from a raw pointer to an integer produces the machine address of the referenced memory.

0 commit comments

Comments
 (0)