pub unsafe trait ViaRawPointer {
type Target: ?Sized;
// Required methods
fn into_raw(self) -> *mut Self::Target;
unsafe fn from_raw(ptr: *mut Self::Target) -> Self;
}
Expand description
Trait for types that can be converted into raw pointers and back again.
§Safety
- Implementors must ensure that, for a given object, the pointer remains fixed as long as no mutable operations are performed (that is, calling from_ptr() followed by into_ptr(), with no mutable operations in between, the returned pointer has the same value.)
- Implementors also must not panic when the interface is used correctly. The Waker constructed by IntoWaker can cause a double drop if either of these functions panic.
In the future, we hope to have a similar trait added to the standard library; see https://github.com/rust-lang/rust/issues/75846 for details.
Required Associated Types§
Required Methods§
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.