[][src]Trait ptrplus::AsPtr

pub trait AsPtr {
    type Raw;
    pub fn as_ptr(&self) -> *const Self::Raw;
}

Trait for types that implement as_ptr.

This is implemented by types which can be converted to a pointer from a borrowed reference.

Example

use ptrplus::AsPtr;

let x: &u32 = &5;
let y: *const u32 = x.as_ptr();
unsafe {
    assert_eq!(*y, 5);
}
use ptrplus::AsPtr;

let x = 5;
let o1: Option<&u32> = None;
let o2: Option<&u32> = Some(&x);

assert!(o1.as_ptr().is_null());
assert!(!o2.as_ptr().is_null());
unsafe {
    assert_eq!(*o2.as_ptr(), 5);
}

Associated Types

type Raw[src]

The type pointed to

as_ptr will return a pointer to this type

Loading content...

Required methods

pub fn as_ptr(&self) -> *const Self::Raw[src]

Returns a raw pointer to the contained content

The caller must ensure self outlives the pointer that is returned, or else it will end up pointing to garbage.

Mutating self may also invalidate this pointer, depending on the implementation.

Loading content...

Implementations on Foreign Types

impl<T> AsPtr for [T][src]

type Raw = T

impl<'a, T: Sized> AsPtr for &'a T where
    T: Sized
[src]

type Raw = T

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

type Raw = T

impl<T> AsPtr for *const T[src]

type Raw = T

impl AsPtr for CStr[src]

type Raw = c_char

impl AsPtr for CString[src]

type Raw = c_char

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

type Raw = T

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

type Raw = T::Raw

impl<T> AsPtr for Cell<T>[src]

type Raw = T

impl<T> AsPtr for RefCell<T>[src]

type Raw = T

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

type Raw = T

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

type Raw = T

Loading content...

Implementors

Loading content...