pub trait AsPtr {
type Raw: ?Sized;
// Required method
fn as_ptr(&self) -> *const Self::Raw;
}Expand description
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);
}