[−][src]Trait ptrplus::AsPtr
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
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.
Implementations on Foreign Types
impl<T> AsPtr for [T]
[src]
impl<'a, T: Sized> AsPtr for &'a T where
T: Sized,
[src]
T: Sized,
impl<T> AsPtr for NonNull<T>
[src]
impl<T> AsPtr for *const T
[src]
impl AsPtr for CStr
[src]
impl AsPtr for CString
[src]
impl<T> AsPtr for Box<T>
[src]
impl<T> AsPtr for Option<T> where
T: AsPtr,
[src]
T: AsPtr,