File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -401,6 +401,18 @@ Casts to the `char` with the corresponding code point.
401401Casting from a pointer to unsized type to pointer to sized type discards the pointer metadata, resulting in just a pointer to the referenced memory.
402402Casting 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
406418Casting from a raw pointer to an integer produces the machine address of the referenced memory.
You can’t perform that action at this time.
0 commit comments