util: use handle_alloc_error()
This commit is contained in:
parent
a205bbb1d2
commit
4f5b90400e
1 changed files with 5 additions and 1 deletions
|
@ -1,5 +1,9 @@
|
|||
use alloc::alloc;
|
||||
|
||||
#[inline]
|
||||
pub fn must_succeed<T>(p: *mut T) -> *mut T {
|
||||
assert!(!p.is_null(), "allocation failure");
|
||||
if p.is_null() {
|
||||
alloc::handle_alloc_error(alloc::Layout::new::<T>())
|
||||
}
|
||||
p
|
||||
}
|
||||
|
|
Reference in a new issue