RawPointerConverter

Trait RawPointerConverter 

Source
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§

Source

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.

Source

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.

Source

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

Source

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§

Source

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

Source

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.

Implementations on Foreign Types§

Source§

impl RawPointerConverter<c_void> for CString

Source§

impl RawPointerConverter<bool> for bool

Source§

impl RawPointerConverter<f32> for f32

Source§

impl RawPointerConverter<f64> for f64

Source§

impl RawPointerConverter<i8> for CString

Source§

impl RawPointerConverter<i16> for i16

Source§

impl RawPointerConverter<i32> for i32

Source§

impl RawPointerConverter<i64> for i64

Source§

impl RawPointerConverter<u16> for u16

Source§

impl RawPointerConverter<u32> for u32

Source§

impl RawPointerConverter<u64> for u64

Source§

impl RawPointerConverter<usize> for usize

Implementors§