@@ -397,35 +397,7 @@ impl<T: ?Sized> *const T {
397
397
if self . is_null ( ) { None } else { Some ( unsafe { & * ( self as * const MaybeUninit < T > ) } ) }
398
398
}
399
399
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" ) ]
429
401
///
430
402
/// # Examples
431
403
///
@@ -905,38 +877,7 @@ impl<T: ?Sized> *const T {
905
877
}
906
878
}
907
879
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" ) ]
940
881
///
941
882
/// # Examples
942
883
///
@@ -1609,6 +1550,7 @@ impl<T> *const [T] {
1609
1550
unsafe { index. get_unchecked ( self ) }
1610
1551
}
1611
1552
1553
+
1612
1554
/// Returns `None` if the pointer is null, or else returns a shared slice to
1613
1555
/// the value wrapped in `Some`. In contrast to [`as_ref`], this does not require
1614
1556
/// that the value has to be initialized.
0 commit comments