@@ -397,35 +397,7 @@ impl<T: ?Sized> *const T {
397397 if self . is_null ( ) { None } else { Some ( unsafe { & * ( self as * const MaybeUninit < T > ) } ) }
398398 }
399399
400- /// Adds a signed offset to a pointer.
401- ///
402- /// `count` is in units of T; e.g., a `count` of 3 represents a pointer
403- /// offset of `3 * size_of::<T>()` bytes.
404- ///
405- /// # Safety
406- ///
407- /// If any of the following conditions are violated, the result is Undefined Behavior:
408- ///
409- /// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
410- /// "wrapping around"), must fit in an `isize`.
411- ///
412- /// * If the computed offset is non-zero, then `self` must be [derived from][crate::ptr#provenance] a pointer to some
413- /// [allocated object], and the entire memory range between `self` and the result must be in
414- /// bounds of that allocated object. In particular, this range must not "wrap around" the edge
415- /// of the address space. Note that "range" here refers to a half-open range as usual in Rust,
416- /// i.e., `self..result` for non-negative offsets and `result..self` for negative offsets.
417- ///
418- /// Allocated objects can never be larger than `isize::MAX` bytes, so if the computed offset
419- /// stays in bounds of the allocated object, it is guaranteed to satisfy the first requirement.
420- /// This implies, for instance, that `vec.as_ptr().add(vec.len())` (for `vec: Vec<T>`) is always
421- /// safe.
422- ///
423- /// Consider using [`wrapping_offset`] instead if these constraints are
424- /// difficult to satisfy. The only advantage of this method is that it
425- /// enables more aggressive compiler optimizations.
426- ///
427- /// [`wrapping_offset`]: #method.wrapping_offset
428- /// [allocated object]: crate::ptr#allocated-object
400+ #[ doc = include_str ! ( "./docs/offset.md" ) ]
429401 ///
430402 /// # Examples
431403 ///
@@ -905,38 +877,7 @@ impl<T: ?Sized> *const T {
905877 }
906878 }
907879
908- /// Adds an unsigned offset to a pointer.
909- ///
910- /// This can only move the pointer forward (or not move it). If you need to move forward or
911- /// backward depending on the value, then you might want [`offset`](#method.offset) instead
912- /// which takes a signed offset.
913- ///
914- /// `count` is in units of T; e.g., a `count` of 3 represents a pointer
915- /// offset of `3 * size_of::<T>()` bytes.
916- ///
917- /// # Safety
918- ///
919- /// If any of the following conditions are violated, the result is Undefined Behavior:
920- ///
921- /// * The offset in bytes, `count * size_of::<T>()`, computed on mathematical integers (without
922- /// "wrapping around"), must fit in an `isize`.
923- ///
924- /// * If the computed offset is non-zero, then `self` must be [derived from][crate::ptr#provenance] a pointer to some
925- /// [allocated object], and the entire memory range between `self` and the result must be in
926- /// bounds of that allocated object. In particular, this range must not "wrap around" the edge
927- /// of the address space.
928- ///
929- /// Allocated objects can never be larger than `isize::MAX` bytes, so if the computed offset
930- /// stays in bounds of the allocated object, it is guaranteed to satisfy the first requirement.
931- /// This implies, for instance, that `vec.as_ptr().add(vec.len())` (for `vec: Vec<T>`) is always
932- /// safe.
933- ///
934- /// Consider using [`wrapping_add`] instead if these constraints are
935- /// difficult to satisfy. The only advantage of this method is that it
936- /// enables more aggressive compiler optimizations.
937- ///
938- /// [`wrapping_add`]: #method.wrapping_add
939- /// [allocated object]: crate::ptr#allocated-object
880+ #[ doc = include_str ! ( "./docs/add.md" ) ]
940881 ///
941882 /// # Examples
942883 ///
@@ -1609,6 +1550,7 @@ impl<T> *const [T] {
16091550 unsafe { index. get_unchecked ( self ) }
16101551 }
16111552
1553+
16121554 /// Returns `None` if the pointer is null, or else returns a shared slice to
16131555 /// the value wrapped in `Some`. In contrast to [`as_ref`], this does not require
16141556 /// that the value has to be initialized.
0 commit comments