mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-04 17:22:19 +00:00
also use shared pointer offset/add/sub docs for NonNull
This commit is contained in:
@@ -330,6 +330,10 @@ impl<T: PointeeSized> *const T {
|
||||
|
||||
#[doc = include_str!("./docs/offset.md")]
|
||||
///
|
||||
/// Consider using [`wrapping_offset`](#method.wrapping_offset) instead if these constraints are
|
||||
/// difficult to satisfy. The only advantage of this method is that it
|
||||
/// enables more aggressive compiler optimizations.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@@ -810,6 +814,10 @@ impl<T: PointeeSized> *const T {
|
||||
|
||||
#[doc = include_str!("./docs/add.md")]
|
||||
///
|
||||
/// Consider using [`wrapping_add`](#method.wrapping_add) instead if these constraints are
|
||||
/// difficult to satisfy. The only advantage of this method is that it
|
||||
/// enables more aggressive compiler optimizations.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@@ -885,6 +893,10 @@ impl<T: PointeeSized> *const T {
|
||||
|
||||
#[doc = include_str!("./docs/sub.md")]
|
||||
///
|
||||
/// Consider using [`wrapping_sub`](#method.wrapping_sub) instead if these constraints are
|
||||
/// difficult to satisfy. The only advantage of this method is that it
|
||||
/// enables more aggressive compiler optimizations.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
|
||||
@@ -25,9 +25,4 @@ Allocations can never be larger than `isize::MAX` bytes and they can only contai
|
||||
representable by `usize`, so technically the last condition implies the first two. This implies, for
|
||||
instance, that `vec.as_ptr().add(vec.len())` (for `vec: Vec<T>`) is always safe.
|
||||
|
||||
Consider using [`wrapping_add`] instead if these constraints are
|
||||
difficult to satisfy. The only advantage of this method is that it
|
||||
enables more aggressive compiler optimizations.
|
||||
|
||||
[`wrapping_add`]: #method.wrapping_add
|
||||
[allocation]: crate::ptr#allocation
|
||||
|
||||
@@ -22,9 +22,4 @@ Allocations can never be larger than `isize::MAX` bytes and they can only contai
|
||||
representable by `usize`, so technically the last condition implies the first two. This implies, for
|
||||
instance, that `vec.as_ptr().offset(vec.len() as isize)` (for `vec: Vec<T>`) is always safe.
|
||||
|
||||
Consider using [`wrapping_offset`] instead if these constraints are
|
||||
difficult to satisfy. The only advantage of this method is that it
|
||||
enables more aggressive compiler optimizations.
|
||||
|
||||
[`wrapping_offset`]: #method.wrapping_offset
|
||||
[allocation]: crate::ptr#allocation
|
||||
|
||||
@@ -24,9 +24,4 @@ This must fit in a `usize`.
|
||||
Allocations can never be larger than `isize::MAX` bytes and they can only contain addresses
|
||||
representable by `usize`, so technically the last condition implies the first two.
|
||||
|
||||
Consider using [`wrapping_sub`] instead if these constraints are
|
||||
difficult to satisfy. The only advantage of this method is that it
|
||||
enables more aggressive compiler optimizations.
|
||||
|
||||
[`wrapping_sub`]: #method.wrapping_sub
|
||||
[allocation]: crate::ptr#allocation
|
||||
|
||||
@@ -333,6 +333,10 @@ impl<T: PointeeSized> *mut T {
|
||||
|
||||
#[doc = include_str!("./docs/offset.md")]
|
||||
///
|
||||
/// Consider using [`wrapping_offset`](#method.wrapping_offset) instead if these constraints are
|
||||
/// difficult to satisfy. The only advantage of this method is that it
|
||||
/// enables more aggressive compiler optimizations.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@@ -908,6 +912,10 @@ impl<T: PointeeSized> *mut T {
|
||||
|
||||
#[doc = include_str!("./docs/add.md")]
|
||||
///
|
||||
/// Consider using [`wrapping_add`](#method.wrapping_add) instead if these constraints are
|
||||
/// difficult to satisfy. The only advantage of this method is that it
|
||||
/// enables more aggressive compiler optimizations.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@@ -983,6 +991,10 @@ impl<T: PointeeSized> *mut T {
|
||||
|
||||
#[doc = include_str!("./docs/sub.md")]
|
||||
///
|
||||
/// Consider using [`wrapping_sub`](#method.wrapping_sub) instead if these constraints are
|
||||
/// difficult to satisfy. The only advantage of this method is that it
|
||||
/// enables more aggressive compiler optimizations.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
|
||||
@@ -528,28 +528,7 @@ impl<T: PointeeSized> NonNull<T> {
|
||||
if self.is_aligned_to(align_of::<U>()) { Some(self.cast()) } else { None }
|
||||
}
|
||||
|
||||
/// Adds an offset to a pointer.
|
||||
///
|
||||
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
|
||||
/// offset of `3 * size_of::<T>()` bytes.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// If any of the following conditions are violated, the result is Undefined Behavior:
|
||||
///
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
|
||||
///
|
||||
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
|
||||
/// [allocation], and the entire memory range between `self` and the result must be in
|
||||
/// bounds of that allocation. In particular, this range must not "wrap around" the edge
|
||||
/// of the address space.
|
||||
///
|
||||
/// Allocations can never be larger than `isize::MAX` bytes, so if the computed offset
|
||||
/// stays in bounds of the allocation, it is guaranteed to satisfy the first requirement.
|
||||
/// This implies, for instance, that `vec.as_ptr().add(vec.len())` (for `vec: Vec<T>`) is always
|
||||
/// safe.
|
||||
///
|
||||
/// [allocation]: crate::ptr#allocation
|
||||
#[doc = include_str!("./docs/offset.md")]
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@@ -604,28 +583,7 @@ impl<T: PointeeSized> NonNull<T> {
|
||||
unsafe { transmute(self.as_ptr().byte_offset(count)) }
|
||||
}
|
||||
|
||||
/// Adds an offset to a pointer (convenience for `.offset(count as isize)`).
|
||||
///
|
||||
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
|
||||
/// offset of `3 * size_of::<T>()` bytes.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// If any of the following conditions are violated, the result is Undefined Behavior:
|
||||
///
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
|
||||
///
|
||||
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
|
||||
/// [allocation], and the entire memory range between `self` and the result must be in
|
||||
/// bounds of that allocation. In particular, this range must not "wrap around" the edge
|
||||
/// of the address space.
|
||||
///
|
||||
/// Allocations can never be larger than `isize::MAX` bytes, so if the computed offset
|
||||
/// stays in bounds of the allocation, it is guaranteed to satisfy the first requirement.
|
||||
/// This implies, for instance, that `vec.as_ptr().add(vec.len())` (for `vec: Vec<T>`) is always
|
||||
/// safe.
|
||||
///
|
||||
/// [allocation]: crate::ptr#allocation
|
||||
#[doc = include_str!("./docs/add.md")]
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@@ -680,29 +638,7 @@ impl<T: PointeeSized> NonNull<T> {
|
||||
unsafe { transmute(self.as_ptr().byte_add(count)) }
|
||||
}
|
||||
|
||||
/// Subtracts an offset from a pointer (convenience for
|
||||
/// `.offset((count as isize).wrapping_neg())`).
|
||||
///
|
||||
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
|
||||
/// offset of `3 * size_of::<T>()` bytes.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// If any of the following conditions are violated, the result is Undefined Behavior:
|
||||
///
|
||||
/// * The computed offset, `count * size_of::<T>()` bytes, must not overflow `isize`.
|
||||
///
|
||||
/// * If the computed offset is non-zero, then `self` must be derived from a pointer to some
|
||||
/// [allocation], and the entire memory range between `self` and the result must be in
|
||||
/// bounds of that allocation. In particular, this range must not "wrap around" the edge
|
||||
/// of the address space.
|
||||
///
|
||||
/// Allocations can never be larger than `isize::MAX` bytes, so if the computed offset
|
||||
/// stays in bounds of the allocation, it is guaranteed to satisfy the first requirement.
|
||||
/// This implies, for instance, that `vec.as_ptr().add(vec.len())` (for `vec: Vec<T>`) is always
|
||||
/// safe.
|
||||
///
|
||||
/// [allocation]: crate::ptr#allocation
|
||||
#[doc = include_str!("./docs/sub.md")]
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user