Skip to main content

PtrMagic

Trait PtrMagic 

Source
pub trait PtrMagic: Sized {
    // Provided methods
    fn into_raw(self) -> *mut Self { ... }
    fn from_raw(ptr: *mut Self) -> Self { ... }
    unsafe fn from_borrow<'a>(ptr: *mut Self) -> &'a mut Self { ... }
}
Expand description

A shared trait for converting from/to a pointer. Specifically a (* mut Self)

Provided Methods§

Source

fn into_raw(self) -> *mut Self

Moves the object to the heap and returns a raw pointer. Caller owns this memory but don’t worry about freeing it. The library frees it somewhere.

Source

fn from_raw(ptr: *mut Self) -> Self

Safety: Only call this on a pointer created via into_raw.

Source

unsafe fn from_borrow<'a>(ptr: *mut Self) -> &'a mut Self

Build from a Ptr but only get a reference, this means that the caller will still own the memory

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.

Implementors§