Function aligned_ptr::ptr::try_copy_nonoverlapping [−][src]
pub unsafe fn try_copy_nonoverlapping<T>(
src: *const T,
dst: *mut T,
count: usize
) -> Result<()>
Expand description
The wrapper of core::ptr::copy_nonoverlapping
which returns an error unless the passed
pointers are aligned and not null.
Safety
The caller must follow the safety rules required by core::ptr::copy_nonoverlapping
except
the alignment and null rules.
Errors
This function may return an error:
crate::Error::Null
- Eithersrc
ordst
is null.crate::Error::NotAligned
- Eithersrc
ordst
is not aligned.
Examples
use aligned_ptr::ptr; use aligned_ptr::Error; use core::mem::MaybeUninit; let x = 3; let src = &x as *const i32; let mut y = MaybeUninit::uninit(); let dst = y.as_mut_ptr(); let r = unsafe { ptr::try_copy_nonoverlapping(src, dst, 1) }; assert!(r.is_ok()); let y = unsafe { y.assume_init() }; assert_eq!(y, 3); let dst = core::ptr::null_mut(); let r = unsafe { ptr::try_copy_nonoverlapping(src, dst, 1) }; assert_eq!(r, Err(Error::Null)); let dst = 0x1001 as *mut i32; let r = unsafe { ptr::try_copy_nonoverlapping(src, dst, 1) }; assert_eq!(r, Err(Error::NotAligned));