IntoRaw

Trait IntoRaw 

Source
pub trait IntoRaw {
    type Raw: ?Sized;

    // Required method
    fn into_raw(self) -> *mut Self::Raw;
}
Expand description

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());
}

Required Associated Types§

Source

type Raw: ?Sized

The type pointed to

into_raw returns a mutable pointer to this type

Required Methods§

Source

fn into_raw(self) -> *mut Self::Raw

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

Implementations on Foreign Types§

Source§

impl IntoRaw for CString

Source§

impl<T> IntoRaw for Option<T>
where T: IntoRaw, T::Raw: Sized,

Source§

type Raw = <T as IntoRaw>::Raw

Source§

fn into_raw(self) -> *mut T::Raw

Source§

impl<T: ?Sized> IntoRaw for *mut T

Source§

type Raw = T

Source§

fn into_raw(self) -> *mut T

Source§

impl<T: ?Sized> IntoRaw for Box<T>

Source§

type Raw = T

Source§

fn into_raw(self) -> *mut T

Source§

impl<T: ?Sized> IntoRaw for Rc<T>

Source§

type Raw = T

Source§

fn into_raw(self) -> *mut T

Source§

impl<T: ?Sized> IntoRaw for Arc<T>

Source§

type Raw = T

Source§

fn into_raw(self) -> *mut T

Source§

impl<T: ?Sized> IntoRaw for NonNull<T>

Source§

type Raw = T

Source§

fn into_raw(self) -> *mut T

Implementors§