pub unsafe trait PointerLike {
type Pointee;
// Required methods
fn into_ptr(self) -> *mut Self::Pointee;
unsafe fn from_ptr(ptr: *mut Self::Pointee) -> Self;
}
Expand description
Trait to convert various kinds of smart pointers and references into a single raw pointer. Allows to implement more generic API.
§Safety
Implementation of this trait must satisfy several safety requirements:
- A raw pointer returned from
PointerLike::into_ptr
and passed toPointerLike::from_ptr
must not be null; - The target type shall not be subtyped or unsized unless explicitly allowed otherwise;
- A raw pointer passed to
Self::from_ptr
shall be returned fromSelf::into_ptr
implementation of the same type unless explicitly allowed; - A raw pointer may be able to outlive lifetime of the original smart pointer, so user shall consider such pointer invalid outside of the original lifetime.
Required Associated Types§
Required Methods§
Sourcefn into_ptr(self) -> *mut Self::Pointee
fn into_ptr(self) -> *mut Self::Pointee
Convert smart pointer into a raw pointer, possibly leaking it.
§Safety
Dereferencing the returned pointer in any manner, writing to it or reading from it is disallowed unless it is specified otherwise.
Sourceunsafe fn from_ptr(ptr: *mut Self::Pointee) -> Self
unsafe fn from_ptr(ptr: *mut Self::Pointee) -> Self
Convert a raw pointer back into a smart pointer.
§Safety
ptr
must be one returned from Self::into_ptr
unless
explicitly allowed otherwise. Be careful raw pointer must not
outlive original smart pointer’s lifetime. Do not call this
function twice on the same argument.
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.