Ptr

Struct Ptr 

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

A raw pointer with more restrictions.

Ptr<T> is similar to NonNull<T>, but it is more restrictive in the following ways (note that these requirements only hold of non-zero-sized referents):

  • It must derive from a valid allocation.
  • It must reference a byte range which is contained inside the allocation from which it derives.
    • As a consequence, the byte range it references must have a size which does not overflow isize.

Depending on how Ptr is parameterized, it may have additional invariants:

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

Implementations§

Source§

impl<'a, T> Ptr<'a, T, (Shared, Aligned, Valid)>
where T: 'a + ?Sized,

This impl block contains no items.

&'a TPtr<'a, T>

Source§

impl<'a, T> Ptr<'a, T, (Exclusive, Aligned, Valid)>
where T: 'a + ?Sized,

This impl block contains no items.

&'a mut TPtr<'a, T>

Source§

impl<'a, T, I> Ptr<'a, T, I>
where T: 'a + ?Sized, I: Invariants<Alignment = Aligned, Validity = Valid>, <I as Invariants>::Aliasing: Reference,

This impl block contains no items.

Ptr<'a, T>&'a T

Source§

impl<'a, T> Ptr<'a, T, (Exclusive, Aligned, Valid)>
where T: 'a + ?Sized,

This impl block contains no items.

Ptr<'a, T>&'a mut T

Source§

impl<'a, T, I> Ptr<'a, T, I>
where I: Invariants, T: ?Sized,

This impl block contains no items.

Ptr<'a, T>Ptr<'a, U>

Source§

impl<'a, T, I> Ptr<'a, T, I>
where I: Invariants,

This impl block contains no items.

Ptr<'a, T, (_, _, _)>Ptr<'a, Unalign<T>, (_, Aligned, _)>

Source§

impl<'a, T, I> Ptr<'a, T, I>
where I: Invariants<Validity = Valid>, <I as Invariants>::Aliasing: Reference, T: ?Sized,

Source

pub fn read_unaligned<R>(self) -> T
where T: Copy + Read<<I as Invariants>::Aliasing, R>,

Reads the referent.

Source

pub fn unaligned_as_ref(self) -> &'a T
where T: Unaligned,

Views the value as an aligned reference.

This is only available if T is [Unaligned].

Source§

impl<'a, I> Ptr<'a, [u8], I>
where I: Invariants<Validity = Valid>,

This impl block contains no items.

For caller convenience, these methods are generic over alignment invariant. In practice, the referent is always well-aligned, because the alignment of [u8] is 1.

Source§

impl<'a, T, I> Ptr<'a, UnsafeCell<T>, I>
where T: 'a + ?Sized, I: Invariants<Aliasing = Exclusive>,

Source

pub fn get_mut(self) -> Ptr<'a, T, I>

Converts this Ptr into a pointer to the underlying data.

This call borrows the UnsafeCell mutably (at compile-time) which guarantees that we possess the only reference.

This is like UnsafeCell::get_mut, but for Ptr.

Trait Implementations§

Source§

impl<'a, T, I> Clone for Ptr<'a, T, I>
where T: 'a + ?Sized, I: Invariants<Aliasing = Shared>,

SAFETY: See the safety comment on Copy.

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, T, I> Debug for Ptr<'a, T, I>
where T: 'a + ?Sized, I: Invariants,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a, T, I> Copy for Ptr<'a, T, I>
where T: 'a + ?Sized, I: Invariants<Aliasing = Shared>,

SAFETY: Shared pointers are safely Copy. Ptr’s other invariants (besides aliasing) are unaffected by the number of references that exist to Ptr’s referent. The notable cases are:

  • Alignment is a property of the referent type (T) and the address, both of which are unchanged

  • Let S(T, V) be the set of bit values permitted to appear in the referent of a Ptr<T, I: Invariants<Validity = V>>. Since this copy does not change I::Validity or T, S(T, I::Validity) is also unchanged.

    We are required to guarantee that the referents of the original Ptr and of the copy (which, of course, are actually the same since they live in the same byte address range) both remain in the set S(T, I::Validity). Since this invariant holds on the original Ptr, it cannot be violated by the original Ptr, and thus the original Ptr cannot be used to violate this invariant on the copy. The inverse holds as well.

Auto Trait Implementations§

§

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

§

impl<'a, T, I> !RefUnwindSafe for Ptr<'a, T, I>

§

impl<'a, T, I> !Send for Ptr<'a, T, I>

§

impl<'a, T, I> !Sync for Ptr<'a, T, I>

§

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

§

impl<'a, T, I> !UnwindSafe for Ptr<'a, T, I>

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<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> 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.