abi_stable::pointer_trait

Trait ImmutableRef

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

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.

Implementors§

Source§

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