pub trait BoxExt<T>: Sized {
// Required methods
fn new(x: T, flags: Flags) -> Result<Self, AllocError>;
fn new_uninit(flags: Flags) -> Result<Box<MaybeUninit<T>>, AllocError>;
fn drop_contents(this: Self) -> Box<MaybeUninit<T>>;
}
Expand description
Extensions to Box
.
Required Methods§
sourcefn new(x: T, flags: Flags) -> Result<Self, AllocError>
fn new(x: T, flags: Flags) -> Result<Self, AllocError>
Allocates a new box.
The allocation may fail, in which case an error is returned.
sourcefn new_uninit(flags: Flags) -> Result<Box<MaybeUninit<T>>, AllocError>
fn new_uninit(flags: Flags) -> Result<Box<MaybeUninit<T>>, AllocError>
Allocates a new uninitialised box.
The allocation may fail, in which case an error is returned.
sourcefn drop_contents(this: Self) -> Box<MaybeUninit<T>>
fn drop_contents(this: Self) -> Box<MaybeUninit<T>>
Drops the contents, but keeps the allocation.
§Examples
use kernel::alloc::{flags, box_ext::BoxExt};
let value = Box::new([0; 32], flags::GFP_KERNEL)?;
assert_eq!(*value, [0; 32]);
let mut value = Box::drop_contents(value);
// Now we can re-use `value`:
value.write([1; 32]);
// SAFETY: We just wrote to it.
let value = unsafe { value.assume_init() };
assert_eq!(*value, [1; 32]);
Object Safety§
This trait is not object safe.