Trait abi_stable::pointer_trait::ImmutableRef [−][src]
pub unsafe trait ImmutableRef: Copy {
type Target;
const TARGET: ImmutableRefTarget<Self, Self::Target>;
fn to_nonnull(self) -> NonNull<Self::Target> { ... }
unsafe fn from_nonnull(from: NonNull<Self::Target>) -> Self { ... }
fn to_raw_ptr(self) -> *const Self::Target { ... }
unsafe fn from_raw_ptr(from: *const Self::Target) -> Option<Self> { ... }
}
Expand description
Trait for non-owning pointers that are shared-reference-like.
Safety
Implementors must be #[repr(transparent)]
wrappers around
&
/NonNull
/impl ImmutableRef
,
with any amount of 1-aligned zero-sized fields.
It must be valid to transmute a NonNull<Self::Target>
pointer obtained
from Self::to_nonnull
back into Self
,
producing a pointer just as usable as the original.
Associated Types
Associated Constants
const TARGET: ImmutableRefTarget<Self, Self::Target>
const TARGET: ImmutableRefTarget<Self, Self::Target>
A marker type that can be used as a proof that the T
type parameter of
ImmutableRefTarget<T, U>
implements ImmutableRef<Target = U>
.
Provided methods
fn to_nonnull(self) -> NonNull<Self::Target>
fn to_nonnull(self) -> NonNull<Self::Target>
Converts this pointer to a NonNull
.
unsafe fn from_nonnull(from: NonNull<Self::Target>) -> Self
unsafe fn from_nonnull(from: NonNull<Self::Target>) -> Self
Constructs this pointer from a NonNull
.
Safety
from
must be a pointer from a call to ImmutableRef::to_nonnull
or
ImmutableRef::to_raw_ptr
on an instance of Self
.
fn to_raw_ptr(self) -> *const Self::Target
fn to_raw_ptr(self) -> *const Self::Target
Converts this pointer to a raw pointer.
unsafe fn from_raw_ptr(from: *const Self::Target) -> Option<Self>
unsafe fn from_raw_ptr(from: *const Self::Target) -> Option<Self>
Constructs this pointer from a raw pointer.
Safety
This has the same safety requirements as from_nonnull