pub unsafe trait ImmutableRef: Copy + GetPointerKind<Kind = PK_Reference> {
    // Provided methods
    fn to_nonnull(self) -> NonNull<Self::PtrTarget> { ... }
    unsafe fn from_nonnull(from: NonNull<Self::PtrTarget>) -> Self { ... }
    fn to_raw_ptr(self) -> *const Self::PtrTarget { ... }
    unsafe fn from_raw_ptr(from: *const Self::PtrTarget) -> Option<Self> { ... }
}
Expand description

Trait for non-owning pointers that are shared-reference-like.

Safety

As implied by GetPointerKind<Kind = PK_Reference>, implementors must be #[repr(transparent)] wrappers around references, and semantically act like references.

Provided Methods§

source

fn to_nonnull(self) -> NonNull<Self::PtrTarget>

Converts this pointer to a NonNull.

source

unsafe fn from_nonnull(from: NonNull<Self::PtrTarget>) -> Self

Constructs this pointer from a NonNull.

Safety

from must be a non-dangling pointer from a call to to_nonnull or to_raw_ptr on an instance of Self or a compatible pointer type.

source

fn to_raw_ptr(self) -> *const Self::PtrTarget

Converts this pointer to a raw pointer.

source

unsafe fn from_raw_ptr(from: *const Self::PtrTarget) -> Option<Self>

Constructs this pointer from a raw pointer.

Safety

This has the same safety requirements as from_nonnull, with the exception that null pointers are allowed.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> ImmutableRef for T
where T: Copy + GetPointerKind<Kind = PK_Reference>,