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