Function aligned_ptr::ptr::try_write_volatile [−][src]
pub unsafe fn try_write_volatile<T>(dst: *mut T, src: T) -> Result<()>
Expand description
The wrapper of core::ptr::write_volatile
which returns an error if the passed pointer is
either null or not aligned.
Safety
The caller must follow the safety rules required by core::ptr::write_volatile
except the
alignment and null requirements.
Errors
This function may return an error:
crate::Error::Null
-dst
is null.crate::Error::NotAligned
-dst
is not aligned correctly.
Examples
use aligned_ptr::ptr; use aligned_ptr::Error; let mut x = 0; let r = unsafe { ptr::try_write_volatile(&mut x, 3) }; assert!(r.is_ok()); assert_eq!(x, 3); let p: *mut i32 = core::ptr::null_mut(); let r = unsafe { ptr::try_write_volatile(p, 3) }; assert_eq!(r, Err(Error::Null)); let p = 0x1001 as *mut i32; let r = unsafe { ptr::try_write_volatile(p, 3) }; assert_eq!(r, Err(Error::NotAligned));