pub trait RawPointerConverter<T>: Sized {
// Required methods
fn into_raw_pointer(self) -> *const T;
fn into_raw_pointer_mut(self) -> *mut T;
unsafe fn from_raw_pointer(
input: *const T,
) -> Result<Self, UnexpectedNullPointerError>;
unsafe fn from_raw_pointer_mut(
input: *mut T,
) -> Result<Self, UnexpectedNullPointerError>;
// Provided methods
unsafe fn drop_raw_pointer(
input: *const T,
) -> Result<(), UnexpectedNullPointerError> { ... }
unsafe fn drop_raw_pointer_mut(
input: *mut T,
) -> Result<(), UnexpectedNullPointerError> { ... }
}Expand description
Trait representing the creation of a raw pointer from a struct and the recovery of said pointer.
The from_raw_pointer function should be used only on pointers obtained through the
into_raw_pointer method (and is thus unsafe as we don’t have any way to get insurance of that
from the compiler).
The from_raw_pointer effectively takes back ownership of the pointer. If you didn’t create the
pointer yourself, please use the as_ref method on the raw pointer to borrow it
Required Methods§
Sourcefn into_raw_pointer(self) -> *const T
fn into_raw_pointer(self) -> *const T
Creates a raw pointer from the value and leaks it, you should use Self::from_raw_pointer
or Self::drop_raw_pointer to free the value when you’re done with it.
Sourcefn into_raw_pointer_mut(self) -> *mut T
fn into_raw_pointer_mut(self) -> *mut T
Creates a mutable raw pointer from the value and leaks it, you should use
Self::from_raw_pointer_mut or Self::drop_raw_pointer_mut to free the value when
you’re done with it.
Sourceunsafe fn from_raw_pointer(
input: *const T,
) -> Result<Self, UnexpectedNullPointerError>
unsafe fn from_raw_pointer( input: *const T, ) -> Result<Self, UnexpectedNullPointerError>
Takes back control of a raw pointer created by Self::into_raw_pointer.
§Safety
This method is unsafe because passing it a pointer that was not created by
Self::into_raw_pointer can lead to memory problems. Also note that passing the same pointer
twice to this function will probably result in a double free
Sourceunsafe fn from_raw_pointer_mut(
input: *mut T,
) -> Result<Self, UnexpectedNullPointerError>
unsafe fn from_raw_pointer_mut( input: *mut T, ) -> Result<Self, UnexpectedNullPointerError>
Takes back control of a raw pointer created by Self::into_raw_pointer_mut.
§Safety
This method is unsafe because passing it a pointer that was not created by
Self::into_raw_pointer_mut can lead to memory problems. Also note that passing the same
pointer twice to this function will probably result in a double free
Provided Methods§
Sourceunsafe fn drop_raw_pointer(
input: *const T,
) -> Result<(), UnexpectedNullPointerError>
unsafe fn drop_raw_pointer( input: *const T, ) -> Result<(), UnexpectedNullPointerError>
Takes back control of a raw pointer created by Self::into_raw_pointer and drop it.
§Safety
This method is unsafe for the same reasons as Self::from_raw_pointer
Sourceunsafe fn drop_raw_pointer_mut(
input: *mut T,
) -> Result<(), UnexpectedNullPointerError>
unsafe fn drop_raw_pointer_mut( input: *mut T, ) -> Result<(), UnexpectedNullPointerError>
Takes back control of a raw pointer created by Self::into_raw_pointer_mut and drops it.
§Safety
This method is unsafe for the same reasons a Self::from_raw_pointer_mut
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.