[][src]Trait ptrplus::IntoRaw

pub trait IntoRaw {
    type Raw;
    pub fn into_raw(self) -> *mut Self::Raw;
}

Trait for types that implement into_raw

This is implemented by types that can be converted into a pointer by consuming ownership of the object

Example

use ptrplus::IntoRaw;

let x: Box<u32> = Box::new(5);
let y: *mut u32 = IntoRaw::into_raw(x);
unsafe {
  assert_eq!(*y, 5);
  *y = 6;
  Box::from_raw(y);
}
use ptrplus::{FromRaw, IntoRaw};

let o1: Option<Box<u32>> = None;
let o2: Option<Box<u32>> = Some(Box::new(5));

let p1: *mut u32 = o1.into_raw();
let p2: *mut u32 = o2.into_raw();

assert!(p1.is_null());
assert!(!p2.is_null());
unsafe {
    assert_eq!(*p2, 5);
    let o1: Option<Box<u32>> = Option::from_raw(p1);
    let o2: Option<Box<u32>> = Option::from_raw(p2);
    assert!(o1.is_none());
    assert!(!o2.is_none());
}

Associated Types

type Raw[src]

The type pointed to

into_raw returns a mutable pointer to this type

Loading content...

Required methods

pub fn into_raw(self) -> *mut Self::Raw[src]

Consumes self returning the wrapped raw pointer.

After calling this method, the caller is responsable for making sure any resources attached to this pointer (such as memory) are cleaned up. The proper way to do this is to convert the pointer back to Self.

See FromRaw

Loading content...

Implementations on Foreign Types

impl IntoRaw for CString[src]

type Raw = c_char

impl<T> IntoRaw for *mut T[src]

type Raw = T

impl<T> IntoRaw for NonNull<T>[src]

type Raw = T

impl<T> IntoRaw for Option<T> where
    T: IntoRaw
[src]

type Raw = T::Raw

impl<T> IntoRaw for Box<T>[src]

type Raw = T

impl<T> IntoRaw for Rc<T>[src]

type Raw = T

impl<T> IntoRaw for Arc<T>[src]

type Raw = T

Loading content...

Implementors

Loading content...