Skip to content

Commit 385a54f

Browse files
committed
Rollup merge of rust-lang#33056 - GuillaumeGomez:as_mut_ptr_example, r=steveklabnik
Improve as_mut ptr method example r? @steveklabnik
2 parents 3c14116 + 4d0b0e9 commit 385a54f

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)