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 only contain a non-null pointer (*1).
Meaning that they must be #[repr(transparent)]
wrappers around
&
/NonNull
/impl ImmutableRef
.
(*1) They can also contain any amount of zero-sized fields with an alignement of 1.
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 one of these:
-
A pointer from a call to
ImmutableRef::to_nonnull
orImmutableRef::to_raw_ptr
on an instance ofSelf
, with the same lifetime. -
Valid to transmute to 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