Trait abi_stable::pointer_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§
sourcefn to_nonnull(self) -> NonNull<Self::PtrTarget>
fn to_nonnull(self) -> NonNull<Self::PtrTarget>
Converts this pointer to a NonNull
.
sourceunsafe fn from_nonnull(from: NonNull<Self::PtrTarget>) -> Self
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.
sourcefn to_raw_ptr(self) -> *const Self::PtrTarget
fn to_raw_ptr(self) -> *const Self::PtrTarget
Converts this pointer to a raw pointer.
sourceunsafe fn from_raw_ptr(from: *const Self::PtrTarget) -> Option<Self>
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.