File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -250,6 +250,20 @@ impl<T: ?Sized> *mut T {
250250 /// *first_value = 4;
251251 /// println!("{:?}", s); // It'll print: "[4, 2, 3]".
252252 /// ```
253+ ///
254+ /// # Null-unchecked version
255+ ///
256+ /// If you are sure the pointer can never be null and are looking for some kind of
257+ /// `as_mut_unchecked` that returns the `&mut T` instead of `Option<&mut T>`, know that
258+ /// you can dereference the pointer directly.
259+ ///
260+ /// ```
261+ /// let mut s = [1, 2, 3];
262+ /// let ptr: *mut u32 = s.as_mut_ptr();
263+ /// let first_value = unsafe { &mut *ptr };
264+ /// *first_value = 4;
265+ /// println!("{:?}", s); // It'll print: "[4, 2, 3]".
266+ /// ```
253267 #[ stable( feature = "ptr_as_ref" , since = "1.9.0" ) ]
254268 #[ inline]
255269 pub unsafe fn as_mut < ' a > ( self ) -> Option < & ' a mut T > {
You can’t perform that action at this time.
0 commit comments