Skip to content

Commit 4d0b0e9

Browse files
Improve as_mut ptr method example
1 parent a626400 commit 4d0b0e9

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/libcore/ptr.rs

+3
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ impl<T: ?Sized> *mut T {
459459
/// ```
460460
/// let mut s = [1, 2, 3];
461461
/// let ptr: *mut u32 = s.as_mut_ptr();
462+
/// let first_value = unsafe { ptr.as_mut().unwrap() };
463+
/// *first_value = 4;
464+
/// println!("{:?}", s); // It'll print: "[4, 2, 3]".
462465
/// ```
463466
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
464467
#[inline]

0 commit comments

Comments
 (0)