pub unsafe trait AsPointerToSlice<T> {
// Required method
unsafe fn get_pointer(self_: NonNull<Self>) -> NonNull<T>;
}Expand description
Trait for objects that can be considered a contiguous part of memory. In particular,
the pointer returned by get_pointer() should be interpreted as the pointer to the first
element of a range of elements of type T (basically a C-style array). In some
sense, this is thus the unsafe equivalent of Deref<Target = [T]>.
§Safety
Since we use this to provide iterators that do not follow the natural layout of the data, the following restrictions are necessary:
- Calling multiple times
get_pointer()on the same reference is valid, and all resulting pointers are valid to be dereferenced. - In the above situation, we may also keep multiple mutable references that were obtained by dereferencing the pointers, as long as they don’t alias, i.e. refer to different elements.
- If
Self: SyncthenT: Sendand the above situation should be valid even if the pointers returned byget_pointer()are produced and used from different threads.
Required Methods§
Sourceunsafe fn get_pointer(self_: NonNull<Self>) -> NonNull<T>
unsafe fn get_pointer(self_: NonNull<Self>) -> NonNull<T>
Returns a pointer to the first element of multiple, contiguous Ts.
§Safety
Requires that self_ is a pointer to a valid object of this type. Note that
it is legal to call this function while there exist mutable references to Ts
that were obtained by dereferencing an earlier result of get_pointer(). This
means that in some situations, the passed self_ may not be dereferenced without
violating the aliasing rules.
However, it must be guaranteed that no mutable reference to an part of self_ that
is not pointed to by a result of get_pointer() exists. Immutable references may exist.
For additional detail, see the trait-level doc AsPointerToSlice.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.