Skip to main content

PtrInner

Struct PtrInner 

Source
pub struct PtrInner<'a, T>
where T: ?Sized,
{ /* private fields */ }
Expand description

The inner pointer stored inside a Ptr.

PtrInner<'a, T> is covariant in 'a and invariant in T.

Implementations§

Source§

impl<'a, T> PtrInner<'a, T>
where T: 'a + ?Sized,

Source

pub const unsafe fn new(ptr: NonNull<T>) -> PtrInner<'a, T>

Constructs a Ptr from a NonNull.

§Safety

The caller promises that:

  1. If ptr’s referent is not zero sized, then ptr has valid provenance for its referent, which is entirely contained in some Rust allocation, A.
  2. If ptr’s referent is not zero sized, A is guaranteed to live for at least 'a.
Source

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

pub const fn as_ptr(&self) -> *mut T

Converts this PtrInner<T> to a [*mut T].

Note that this method does not consume self. The caller should watch out for unsafe code which uses the returned *mut T in a way that violates the safety invariants of self.

Source§

impl<'a, T> PtrInner<'a, T>
where T: ?Sized,

Source

pub fn from_ref(ptr: &'a T) -> PtrInner<'a, T>

Constructs a PtrInner from a reference.

Source

pub fn from_mut(ptr: &'a mut T) -> PtrInner<'a, T>

Constructs a PtrInner from a mutable reference.

Source

pub fn project<U, C>(self) -> PtrInner<'a, U>
where C: Project<T, U>, U: ?Sized,

§Safety

The caller may assume that the resulting PtrInner addresses the subset of the bytes of self’s referent addressed by C::project(self).

Source§

impl<'a, T> PtrInner<'a, T>
where T: KnownLayout + ?Sized,

Source

pub fn meta(self) -> MetadataOf<T>

Extracts the metadata of this ptr.

Source

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>
where T: KnownLayout<PointerMetadata = usize> + ?Sized,

Source

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

pub fn trailing_slice(self) -> PtrInner<'a, [<T as SplitAt>::Elem]>
where T: SplitAt,

Produces the trailing slice of self.

Source§

impl<'a, T> PtrInner<'a, [T]>

Source

pub unsafe fn slice_unchecked(self, range: Range<usize>) -> PtrInner<'a, [T]>

Creates a pointer which addresses the given range of self.

§Safety

range is a valid range (start <= end) and end <= self.meta().

Source

pub fn iter(&self) -> impl Iterator<Item = PtrInner<'a, T>>

Iteratively projects the elements PtrInner<T> from PtrInner<[T]>.

Source§

impl<'a, T, const N: usize> PtrInner<'a, [T; N]>

Source

pub fn as_slice(self) -> PtrInner<'a, [T]>

Casts this pointer-to-array into a slice.

§Safety

Callers may assume that the returned PtrInner references the same address and length as self.

Source§

impl<'a> PtrInner<'a, [u8]>

Source

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, ptr has the same address as self.
  • If this is a suffix cast, remainder has the same address as self.

Trait Implementations§

Source§

impl<'a, T> Clone for PtrInner<'a, T>
where T: 'a + ?Sized,

Source§

fn clone(&self) -> PtrInner<'a, T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, T> Copy for PtrInner<'a, T>
where T: 'a + ?Sized,

Auto Trait Implementations§

§

impl<'a, T> !RefUnwindSafe for PtrInner<'a, T>

§

impl<'a, T> !Send for PtrInner<'a, T>

§

impl<'a, T> !Sync for PtrInner<'a, T>

§

impl<'a, T> !UnwindSafe for PtrInner<'a, T>

§

impl<'a, T> Freeze for PtrInner<'a, T>
where T: ?Sized,

§

impl<'a, T> Unpin for PtrInner<'a, T>
where T: ?Sized,

§

impl<'a, T> UnsafeUnpin for PtrInner<'a, T>
where T: ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.