pub type KVBox<T> = Box<T, KVmalloc>;
Expand description
Aliased Type§
struct KVBox<T>(/* private fields */);
Implementations
source§impl<T, A> Box<MaybeUninit<T>, A>where
A: Allocator,
impl<T, A> Box<MaybeUninit<T>, A>where
A: Allocator,
sourcepub unsafe fn assume_init(self) -> Box<T, A>
pub unsafe fn assume_init(self) -> Box<T, A>
Converts a Box<MaybeUninit<T>, A>
to a Box<T, A>
.
It is undefined behavior to call this function while the value inside of b
is not yet
fully initialized.
§Safety
Callers must ensure that the value inside of b
is in an initialized state.
source§impl<T, A> Box<T, A>
impl<T, A> Box<T, A>
sourcepub const unsafe fn from_raw(raw: *mut T) -> Self
pub const unsafe fn from_raw(raw: *mut T) -> Self
Creates a new Box<T, A>
from a raw pointer.
§Safety
For non-ZSTs, raw
must point at an allocation allocated with A
that is sufficiently
aligned for and holds a valid T
. The caller passes ownership of the allocation to the
Box
.
For ZSTs, raw
must be a dangling, well aligned pointer.
sourcepub fn into_raw(b: Self) -> *mut T
pub fn into_raw(b: Self) -> *mut T
Consumes the Box<T, A>
and returns a raw pointer.
This will not run the destructor of T
and for non-ZSTs the allocation will stay alive
indefinitely. Use Box::from_raw
to recover the Box
, drop the value and free the
allocation, if any.
§Examples
let x = KBox::new(24, GFP_KERNEL)?;
let ptr = KBox::into_raw(x);
// SAFETY: `ptr` comes from a previous call to `KBox::into_raw`.
let x = unsafe { KBox::from_raw(ptr) };
assert_eq!(*x, 24);
sourcepub fn leak<'a>(b: Self) -> &'a mut T
pub fn leak<'a>(b: Self) -> &'a mut T
Consumes and leaks the Box<T, A>
and returns a mutable reference.
See Box::into_raw
for more details.
source§impl<T, A> Box<T, A>where
A: Allocator,
impl<T, A> Box<T, A>where
A: Allocator,
sourcepub fn new(x: T, flags: Flags) -> Result<Self, AllocError>
pub fn new(x: T, flags: Flags) -> Result<Self, AllocError>
Creates a new Box<T, A>
and initializes its contents with x
.
New memory is allocated with A
. The allocation may fail, in which case an error is
returned. For ZSTs no memory is allocated.
sourcepub fn new_uninit(flags: Flags) -> Result<Box<MaybeUninit<T>, A>, AllocError>
pub fn new_uninit(flags: Flags) -> Result<Box<MaybeUninit<T>, A>, AllocError>
Creates a new Box<T, A>
with uninitialized contents.
New memory is allocated with A
. The allocation may fail, in which case an error is
returned. For ZSTs no memory is allocated.
§Examples
let b = KBox::<u64>::new_uninit(GFP_KERNEL)?;
let b = KBox::write(b, 24);
assert_eq!(*b, 24_u64);
sourcepub fn pin(x: T, flags: Flags) -> Result<Pin<Box<T, A>>, AllocError>where
A: 'static,
pub fn pin(x: T, flags: Flags) -> Result<Pin<Box<T, A>>, AllocError>where
A: 'static,
Constructs a new Pin<Box<T, A>>
. If T
does not implement Unpin
, then x
will be
pinned in memory and can’t be moved.
sourcepub fn into_pin(this: Self) -> Pin<Self>
pub fn into_pin(this: Self) -> Pin<Self>
Convert a Box<T,A>
to a Pin<Box<T,A>>
. If T
does not implement
Unpin
, then x
will be pinned in memory and can’t be moved.
sourcepub fn drop_contents(this: Self) -> Box<MaybeUninit<T>, A>
pub fn drop_contents(this: Self) -> Box<MaybeUninit<T>, A>
Drops the contents, but keeps the allocation.
§Examples
let value = KBox::new([0; 32], GFP_KERNEL)?;
assert_eq!(*value, [0; 32]);
let value = KBox::drop_contents(value);
// Now we can re-use `value`:
let value = KBox::write(value, [1; 32]);
assert_eq!(*value, [1; 32]);
sourcepub fn into_inner(b: Self) -> T
pub fn into_inner(b: Self) -> T
Moves the Box
’s value out of the Box
and consumes the Box
.
Trait Implementations
source§impl<T: 'static, A> ForeignOwnable for Box<T, A>where
A: Allocator,
impl<T: 'static, A> ForeignOwnable for Box<T, A>where
A: Allocator,
§type BorrowedMut<'a> = &'a mut T
type BorrowedMut<'a> = &'a mut T
source§fn into_foreign(self) -> *mut c_void
fn into_foreign(self) -> *mut c_void
source§unsafe fn from_foreign(ptr: *mut c_void) -> Self
unsafe fn from_foreign(ptr: *mut c_void) -> Self
source§unsafe fn borrow<'a>(ptr: *mut c_void) -> &'a T
unsafe fn borrow<'a>(ptr: *mut c_void) -> &'a T
source§impl<T, A> InPlaceInit<T> for Box<T, A>where
A: Allocator + 'static,
impl<T, A> InPlaceInit<T> for Box<T, A>where
A: Allocator + 'static,
§type PinnedSelf = Pin<Box<T, A>>
type PinnedSelf = Pin<Box<T, A>>
Self
. Read moresource§fn try_pin_init<E>(
init: impl PinInit<T, E>,
flags: Flags
) -> Result<Pin<Self>, E>where
E: From<AllocError>,
fn try_pin_init<E>(
init: impl PinInit<T, E>,
flags: Flags
) -> Result<Pin<Self>, E>where
E: From<AllocError>,
T
inside of a new smart pointer of this
type. Read moresource§fn try_init<E>(init: impl Init<T, E>, flags: Flags) -> Result<Self, E>where
E: From<AllocError>,
fn try_init<E>(init: impl Init<T, E>, flags: Flags) -> Result<Self, E>where
E: From<AllocError>,
T
.source§impl<T, A> InPlaceWrite<T> for Box<MaybeUninit<T>, A>where
A: Allocator + 'static,
impl<T, A> InPlaceWrite<T> for Box<MaybeUninit<T>, A>where
A: Allocator + 'static,
§type Initialized = Box<T, A>
type Initialized = Box<T, A>
Self
turns into when the contents are initialized.source§fn write_init<E>(self, init: impl Init<T, E>) -> Result<Self::Initialized, E>
fn write_init<E>(self, init: impl Init<T, E>) -> Result<Self::Initialized, E>
self
. Read moresource§fn write_pin_init<E>(
self,
init: impl PinInit<T, E>
) -> Result<Pin<Self::Initialized>, E>
fn write_pin_init<E>( self, init: impl PinInit<T, E> ) -> Result<Pin<Self::Initialized>, E>
self
. Read more