[−][src]Trait ptrplus::FromRaw
Trait for types that can be created from a raw pointer
Examples
use ptrplus::{FromRaw, IntoRaw}; let x: Box<u32> = Box::new(5); let y = x.into_raw(); let z: Box<u32> = unsafe { FromRaw::from_raw(y) }; assert_eq!(*z, 5);
Required methods
pub unsafe fn from_raw(raw: *mut T) -> Self
[src]
Create Self
from a raw pointer
After calling this method the raw pointer is owned by the resulting object. This means that the resulting object should clean up any resources associated with the pointer (such as memory).
Safety
raw
must be a pointer that is compatible with
the resulting type. For example, if Self
is
Box<T>
, then raw
must be a pointer to memory allocated
as a Box. The exact requirements depend on the implementation.
Generally, the raw
pointer must be the result of a previous
call to into_raw
on the corresponding type. This the case for
types such as Box
, Rc
, and Arc
. If the documentation
for the implementation does not say otherwise, assume this is the
case.
Additionally, this function takes ownership of the pointer. If
raw
or an alias thereof is used after calling this function
it can potentially result in double-free, data races, or other
undefined behavior.
Implementations on Foreign Types
impl FromRaw<i8> for CString
[src]
Safety: from_raw
should only be called on a pointer originating
from a CString
.
impl<T> FromRaw<T> for *mut T
[src]
This implementation is always safe
impl<T> FromRaw<T> for *const T
[src]
This implementation is always safe
impl<T> FromRaw<T> for NonNull<T>
[src]
Safety
The input pointer must be non-null.
Option<NonNull<T>>::from_raw
can be used if the pointer may be null.
impl<T, U> FromRaw<U> for Option<T> where
T: FromRaw<U>,
[src]
T: FromRaw<U>,
Safety
The input pointer must either be null (resulting in None
), or be safe
to convert into the inner pointer type.