This repository has been archived on 2025-03-02. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
neco/safe_libc/src/util.rs
2020-04-04 14:23:00 +02:00

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
}