@@ -394,34 +394,7 @@ impl<T: ?Sized> *mut T {
394
394
if self . is_null ( ) { None } else { Some ( unsafe { & * ( self as * const MaybeUninit < T > ) } ) }
395
395
}
396
396
397
- /// Adds a signed offset to a pointer.
398
- ///
399
- /// `count` is in units of T; e.g., a `count` of 3 represents a pointer
400
- /// offset of `3 * size_of::<T>()` bytes.
401
- ///
402
- /// # Safety
403
- ///
404
- /// If any of the following conditions are violated, the result is Undefined Behavior:
405
- ///
406
- /// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
407
- /// "wrapping around"), must fit in an `isize`.
408
- ///
409
- /// * If the computed offset is non-zero, then `self` must be [derived from][crate::ptr#provenance] a pointer to some
410
- /// [allocated object], and the entire memory range between `self` and the result must be in
411
- /// bounds of that allocated object. In particular, this range must not "wrap around" the edge
412
- /// of the address space.
413
- ///
414
- /// Allocated objects can never be larger than `isize::MAX` bytes, so if the computed offset
415
- /// stays in bounds of the allocated object, it is guaranteed to satisfy the first requirement.
416
- /// This implies, for instance, that `vec.as_ptr().add(vec.len())` (for `vec: Vec<T>`) is always
417
- /// safe.
418
- ///
419
- /// Consider using [`wrapping_offset`] instead if these constraints are
420
- /// difficult to satisfy. The only advantage of this method is that it
421
- /// enables more aggressive compiler optimizations.
422
- ///
423
- /// [`wrapping_offset`]: #method.wrapping_offset
424
- /// [allocated object]: crate::ptr#allocated-object
397
+ #[ doc = include_str ! ( "./docs/offset.md" ) ]
425
398
///
426
399
/// # Examples
427
400
///
@@ -996,44 +969,13 @@ impl<T: ?Sized> *mut T {
996
969
unsafe { ( self as * const T ) . byte_offset_from_unsigned ( origin) }
997
970
}
998
971
999
- /// Adds an unsigned offset to a pointer.
1000
- ///
1001
- /// This can only move the pointer forward (or not move it). If you need to move forward or
1002
- /// backward depending on the value, then you might want [`offset`](#method.offset) instead
1003
- /// which takes a signed offset.
1004
- ///
1005
- /// `count` is in units of T; e.g., a `count` of 3 represents a pointer
1006
- /// offset of `3 * size_of::<T>()` bytes.
1007
- ///
1008
- /// # Safety
1009
- ///
1010
- /// If any of the following conditions are violated, the result is Undefined Behavior:
1011
- ///
1012
- /// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
1013
- /// "wrapping around"), must fit in an `isize`.
1014
- ///
1015
- /// * If the computed offset is non-zero, then `self` must be [derived from][crate::ptr#provenance] a pointer to some
1016
- /// [allocated object], and the entire memory range between `self` and the result must be in
1017
- /// bounds of that allocated object. In particular, this range must not "wrap around" the edge
1018
- /// of the address space.
1019
- ///
1020
- /// Allocated objects can never be larger than `isize::MAX` bytes, so if the computed offset
1021
- /// stays in bounds of the allocated object, it is guaranteed to satisfy the first requirement.
1022
- /// This implies, for instance, that `vec.as_ptr().add(vec.len())` (for `vec: Vec<T>`) is always
1023
- /// safe.
1024
- ///
1025
- /// Consider using [`wrapping_add`] instead if these constraints are
1026
- /// difficult to satisfy. The only advantage of this method is that it
1027
- /// enables more aggressive compiler optimizations.
1028
- ///
1029
- /// [`wrapping_add`]: #method.wrapping_add
1030
- /// [allocated object]: crate::ptr#allocated-object
972
+ #[ doc = include_str ! ( "./docs/add.md" ) ]
1031
973
///
1032
974
/// # Examples
1033
975
///
1034
976
/// ```
1035
- /// let s: &str = "123";
1036
- /// let ptr: *const u8 = s.as_ptr ();
977
+ /// let mut s: String = "123".to_string() ;
978
+ /// let ptr: *mut u8 = s.as_mut_ptr ();
1037
979
///
1038
980
/// unsafe {
1039
981
/// assert_eq!('2', *ptr.add(1) as char);
0 commit comments