18 lines
398 B
Rust
18 lines
398 B
Rust
use core::mem;
|
|
|
|
#[inline]
|
|
pub fn zst<T>(len: usize) -> bool {
|
|
mem::size_of::<T>() == 0 || len == 0
|
|
}
|
|
|
|
#[inline]
|
|
pub fn check_ptr<T>(p: *const T, len: usize) {
|
|
debug_assert!((p as usize) % mem::align_of::<T>() == 0, "unaligned ptr");
|
|
assert!(zst::<T>(len) || !p.is_null(), "NULL ptr");
|
|
}
|
|
|
|
#[inline]
|
|
pub fn must_succeed<T>(p: *mut T) -> *mut T {
|
|
assert!(!p.is_null(), "allocation failure");
|
|
p
|
|
}
|