Trait haphazard::raw::Pointer

source ·
pub unsafe trait Pointer<T>
where Self: Sized + Deref<Target = T>,
{ // Required methods fn into_raw(self) -> *mut T; unsafe fn from_raw(ptr: *mut T) -> Self; }
Expand description

A type that can be turned into, and converted from, a raw pointer whose referent is T.

Safety

  1. the *mut T returned from into_raw must be valid as a &mut T when it is returned.
  2. the *mut T returned from into_raw must remain valid as a &T until it is passed to from_raw.
  3. from_raw must not return a particular *mut T again until the provided self is dropped after an eventual call to from_raw.

Required Methods§

source

fn into_raw(self) -> *mut T

Extract the raw pointer referenced by self.

source

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

Reconstruct this pointer type from the given ptr.

Safety (for callers)
  1. ptr must be a pointer returned by Self::into_raw
  2. ptr must be valid to dereference to a T
  3. ptr must not have been passed to from_raw since it was returned from into_raw
  4. ptr must not be aliased

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T> Pointer<T> for Box<T>

source§

fn into_raw(self) -> *mut T

source§

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

Implementors§