pub struct PtrInner<'a, T>where
T: ?Sized,{ /* private fields */ }Expand description
Implementations§
Source§impl<'a, T> PtrInner<'a, T>where
T: 'a + ?Sized,
impl<'a, T> PtrInner<'a, T>where
T: 'a + ?Sized,
Sourcepub const fn as_non_null(&self) -> NonNull<T>
pub const fn as_non_null(&self) -> NonNull<T>
Converts this PtrInner<T> to a NonNull<T>.
Note that this method does not consume self. The caller should
watch out for unsafe code which uses the returned NonNull in a
way that violates the safety invariants of self.
Source§impl<'a, T> PtrInner<'a, T>where
T: ?Sized,
impl<'a, T> PtrInner<'a, T>where
T: ?Sized,
Source§impl<'a, T> PtrInner<'a, T>where
T: KnownLayout + ?Sized,
impl<'a, T> PtrInner<'a, T>where
T: KnownLayout + ?Sized,
Sourcepub fn meta(self) -> MetadataOf<T>
pub fn meta(self) -> MetadataOf<T>
Extracts the metadata of this ptr.
Sourcepub unsafe fn with_meta(
self,
meta: <T as KnownLayout>::PointerMetadata,
) -> PtrInner<'a, T>where
T: KnownLayout,
pub unsafe fn with_meta(
self,
meta: <T as KnownLayout>::PointerMetadata,
) -> PtrInner<'a, T>where
T: KnownLayout,
Produces a PtrInner with the same address and provenance as self but
the given meta.
§Safety
The caller promises that if self’s referent is not zero sized, then
a pointer constructed from its address with the given meta metadata
will address a subset of the allocation pointed to by self.
Source§impl<'a, T> PtrInner<'a, T>
impl<'a, T> PtrInner<'a, T>
Sourcepub unsafe fn split_at_unchecked(
self,
l_len: MetadataOf<T>,
) -> (PtrInner<'a, T>, PtrInner<'a, [<T as SplitAt>::Elem]>)where
T: SplitAt,
pub unsafe fn split_at_unchecked(
self,
l_len: MetadataOf<T>,
) -> (PtrInner<'a, T>, PtrInner<'a, [<T as SplitAt>::Elem]>)where
T: SplitAt,
Splits T in two.
§Safety
The caller promises that:
l_len.get() <= self.meta().
§(Non-)Overlap
Given let (left, right) = ptr.split_at(l_len), it is guaranteed that
left and right are contiguous and non-overlapping if
l_len.padding_needed_for() == 0. This is true for all [T].
If l_len.padding_needed_for() != 0, then the left pointer will overlap
the right pointer to satisfy T’s padding requirements.
Source§impl<'a, T> PtrInner<'a, [T]>
impl<'a, T> PtrInner<'a, [T]>
Source§impl<'a> PtrInner<'a, [u8]>
impl<'a> PtrInner<'a, [u8]>
Sourcepub fn try_cast_into<U>(
self,
cast_type: CastType,
meta: Option<<U as KnownLayout>::PointerMetadata>,
) -> Result<(PtrInner<'a, U>, PtrInner<'a, [u8]>), ConvertError<AlignmentError<PtrInner<'a, [u8]>, U>, SizeError<PtrInner<'a, [u8]>, U>, Infallible>>where
U: 'a + KnownLayout + ?Sized,
pub fn try_cast_into<U>(
self,
cast_type: CastType,
meta: Option<<U as KnownLayout>::PointerMetadata>,
) -> Result<(PtrInner<'a, U>, PtrInner<'a, [u8]>), ConvertError<AlignmentError<PtrInner<'a, [u8]>, U>, SizeError<PtrInner<'a, [u8]>, U>, Infallible>>where
U: 'a + KnownLayout + ?Sized,
Attempts to cast self to a U using the given cast type.
If U is a slice DST and pointer metadata (meta) is provided, then
the cast will only succeed if it would produce an object with the given
metadata.
Returns None if the resulting U would be invalidly-aligned, if no
U can fit in self, or if the provided pointer metadata describes an
invalid instance of U. On success, returns a pointer to the
largest-possible U which fits in self.
§Safety
The caller may assume that this implementation is correct, and may rely
on that assumption for the soundness of their code. In particular, the
caller may assume that, if try_cast_into returns Some((ptr, remainder)), then ptr and remainder refer to non-overlapping byte
ranges within self, and that ptr and remainder entirely cover
self. Finally:
- If this is a prefix cast,
ptrhas the same address asself. - If this is a suffix cast,
remainderhas the same address asself.