pub unsafe trait PtrTraits {
type Target;
const IS_MANAGED: bool;
// Required methods
fn into_raw(self) -> *mut Self::Target;
unsafe fn from_raw(raw: *mut Self::Target) -> Self;
fn get_ref(&self) -> &Self::Target;
}Expand description
Trait for pointer types that can be stored in intrusive containers.
§Safety
Implementing this trait is unsafe because the container relies on the correctness of the implementation to maintain memory safety:
into_rawmust return a valid, non-null, and dereferenceable pointer toTargetthat uniquely identifies the object.from_rawmust correctly reconstruct a valid instance ofSelffrom a pointer previously returned byinto_raw.from_rawmust reclaim the ownership previously yielded byinto_raw.get_refmust return a valid reference to theTarget.
Required Associated Constants§
Sourceconst IS_MANAGED: bool
const IS_MANAGED: bool
Whether the pointer type is managed (e.g., UniquePtr or RefPtr).
If the pointer type is managed, containers can be dropped while they are non-empty because the pointers can free the underlying memory. If the pointer is not managed, then the containers need to be empty when they are dropped to avoid memory leaks.
Required Associated Types§
Required Methods§
Sourcefn into_raw(self) -> *mut Self::Target
fn into_raw(self) -> *mut Self::Target
Consumes the pointer and returns a raw pointer to the target.
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.