Struct secmem_alloc::boxed::Box
source · [−]Expand description
A replacement for std::boxed::Box
that works with custom allocators.
See the module-level documentation for more.
Implementations
sourceimpl<T, A: Allocator> Box<T, A>
impl<T, A: Allocator> Box<T, A>
sourcepub fn new_in(x: T, alloc: A) -> Self
pub fn new_in(x: T, alloc: A) -> Self
Allocates memory in the given allocator then places x
into it.
This doesn’t actually allocate if T
is zero-sized.
Examples
#![feature(allocator_api)]
use secmem_alloc::boxed::Box;
use std::alloc::System;
let five = Box::new_in(5, System);
sourcepub fn try_new_in(x: T, alloc: A) -> Result<Self, AllocError>
pub fn try_new_in(x: T, alloc: A) -> Result<Self, AllocError>
Allocates memory in the given allocator then places x
into it,
returning an error if the allocation fails
This doesn’t actually allocate if T
is zero-sized.
Examples
#![feature(allocator_api)]
use secmem_alloc::boxed::Box;
use std::alloc::System;
let five = Box::try_new_in(5, System)?;
sourcepub fn new_uninit_in(alloc: A) -> Box<MaybeUninit<T>, A>
pub fn new_uninit_in(alloc: A) -> Box<MaybeUninit<T>, A>
Constructs a new box with uninitialized contents in the provided allocator.
Examples
#![feature(allocator_api)]
use secmem_alloc::boxed::Box;
use std::alloc::System;
let mut five = Box::<u32, _>::new_uninit_in(System);
let five = unsafe {
// Deferred initialization:
five.as_mut_ptr().write(5);
five.assume_init()
};
assert_eq!(*five, 5)
sourcepub fn try_new_uninit_in(alloc: A) -> Result<Box<MaybeUninit<T>, A>, AllocError>
pub fn try_new_uninit_in(alloc: A) -> Result<Box<MaybeUninit<T>, A>, AllocError>
Constructs a new box with uninitialized contents in the provided allocator, returning an error if the allocation fails
Examples
#![feature(allocator_api)]
use secmem_alloc::boxed::Box;
use std::alloc::System;
let mut five = Box::<u32, _>::try_new_uninit_in(System)?;
let five = unsafe {
// Deferred initialization:
five.as_mut_ptr().write(5);
five.assume_init()
};
assert_eq!(*five, 5);
sourceimpl<T, A: Allocator> Box<MaybeUninit<T>, A>
impl<T, A: Allocator> Box<MaybeUninit<T>, A>
sourcepub unsafe fn assume_init(self) -> Box<T, A>
pub unsafe fn assume_init(self) -> Box<T, A>
Converts to Box<T, A>
.
Safety
As with MaybeUninit::assume_init
,
it is up to the caller to guarantee that the value
really is in an initialized state.
Calling this when the content is not yet fully initialized
causes immediate undefined behavior.
Examples
#![feature(allocator_api)]
use secmem_alloc::boxed::Box;
use std::alloc::System;
let mut five = Box::<u32, _>::new_uninit_in(System);
let five: Box<u32, _> = unsafe {
// Deferred initialization:
five.as_mut_ptr().write(5);
five.assume_init()
};
assert_eq!(*five, 5)
Trait Implementations
Auto Trait Implementations
impl<T: ?Sized, A> RefUnwindSafe for Box<T, A> where
A: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, A> !Send for Box<T, A>
impl<T, A> !Sync for Box<T, A>
impl<T: ?Sized, A> Unpin for Box<T, A> where
A: Unpin,
T: Unpin,
impl<T: ?Sized, A> UnwindSafe for Box<T, A> where
A: UnwindSafe,
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more