[−][src]Struct storages::boxed::Box
Implementations
impl<T> Box<T>
[src]
Construction of boxed values with a buffer backed by the global allocator.
pub fn new(value: T) -> Self
[src]
Allocates memory on the global heap and then places value
into it.
This doesn't actually allocate if T
is zero-sized.
Examples
use storages::boxed::Box; let five = Box::new(5); assert_eq!(*five, 5);
pub fn new_uninit() -> Box<MaybeUninit<T>, AllocatedBuffer<T>>
[src]
Constructs a new raw box with uninitialized contents.
Examples
use storages::boxed::Box; let mut five = Box::<u32>::new_uninit(); let five = unsafe { // Deferred initialization: five.as_mut_ptr().write(5); five.assume_init() }; assert_eq!(*five, 5);
pub fn new_zeroed() -> Box<MaybeUninit<T>, AllocatedBuffer<T>>
[src]
Constructs a new box with uninitialized contents, with the memory being filled with 0
bytes.
See MaybeUninit::zeroed
for examples of correct and incorrect usage of this method.
Examples
use storages::boxed::Box; let zero = Box::<u32>::new_zeroed(); let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0);
impl<T> Box<[T]>
[src]
Construction of boxed slices with a buffer backed by the global allocator.
pub fn new_uninit_slice(
len: usize
) -> Box<[MaybeUninit<T>], AllocatedBuffer<[T]>>
[src]
len: usize
) -> Box<[MaybeUninit<T>], AllocatedBuffer<[T]>>
Constructs a boxed slice with uninitialized contents.
Examples
use storages::boxed::Box; let mut values = Box::<[u32]>::new_uninit_slice(3); let values = unsafe { // Deferred initialization: values[0].as_mut_ptr().write(1); values[1].as_mut_ptr().write(2); values[2].as_mut_ptr().write(3); values.assume_init() }; assert_eq!(&*values, [1, 2, 3])
pub fn new_zeroed_slice(
len: usize
) -> Box<[MaybeUninit<T>], AllocatedBuffer<[T]>>
[src]
len: usize
) -> Box<[MaybeUninit<T>], AllocatedBuffer<[T]>>
Constructs a boxed with uninitialized contents with the memory being filled with 0
bytes.
See MaybeUninit::zeroed
for examples of correct and incorrect usage of this method.
Examples
use storages::boxed::Box; let values = Box::<[u32]>::new_zeroed_slice(3); let values = unsafe { values.assume_init() }; assert_eq!(&*values, [0, 0, 0])
impl<T, B, D> Box<T, B, D> where
B: Buffer<T, ExternalData = D>,
[src]
B: Buffer<T, ExternalData = D>,
Construction of boxed values in a provided buffer.
pub fn new_in(value: T, buffer: B, data: D) -> Self
[src]
Places the value in the provided buffer.
Examples
#![feature(allocator_api)] use std::alloc::System; use storages::{boxed::RawBox, buffer::AllocatedBuffer}; let buffer = AllocatedBuffer::new_in(&System)?; let five = RawBox::new_in(5, buffer, &System); assert_eq!(*five.as_ref(&System), 5);
pub fn new_uninit_in(buffer: B, data: D) -> Box<MaybeUninit<T>, B, D> where
B: Buffer<MaybeUninit<T>, ExternalData = D>,
[src]
B: Buffer<MaybeUninit<T>, ExternalData = D>,
Constructs a new raw box with uninitialized contents in the provided buffer.
Examples
#![feature(allocator_api, maybe_uninit_extra)] use std::alloc::System; use storages::{boxed::RawBox, buffer::AllocatedBuffer}; let buffer = AllocatedBuffer::new_in(&System)?; let mut five = RawBox::<u32, _>::new_uninit_in(buffer); let five = unsafe { // Deferred initialization: five.as_mut(&System).write(5); five.assume_init() }; assert_eq!(*five.as_ref(&System), 5);
impl<T, B, D> Box<[T], B, D> where
B: Buffer<[T], ExternalData = D>,
[src]
B: Buffer<[T], ExternalData = D>,
Construction of boxed slices in a provided buffer.
pub fn new_uninit_slice_in(buffer: B, data: D) -> Box<[MaybeUninit<T>], B, D> where
B: Buffer<[MaybeUninit<T>], ExternalData = D>,
[src]
B: Buffer<[MaybeUninit<T>], ExternalData = D>,
Constructs a boxed with uninitialized contents in the provided buffer.
Examples
use std::mem; use storages::boxed::RawBox; let buffer = [mem::MaybeUninit::<u32>::uninit(); 3]; let mut values = RawBox::new_uninit_slice_in(buffer); let values = unsafe { // Deferred initialization: values[0].as_mut_ptr().write(1); values[1].as_mut_ptr().write(2); values[2].as_mut_ptr().write(3); values.assume_init() }; assert_eq!(*values, [1, 2, 3])
impl<T, B, D> Box<MaybeUninit<T>, B, D> where
B: Buffer<T, ExternalData = D> + Buffer<MaybeUninit<T>, ExternalData = D>,
[src]
B: Buffer<T, ExternalData = D> + Buffer<MaybeUninit<T>, ExternalData = D>,
pub unsafe fn assume_init(self) -> Box<T, B, D>
[src]
Converts to RawBox<T, B>
.
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, maybe_uninit_extra, new_uninit)] use std::alloc::Global; use storages::boxed::RawBox; let mut five = RawBox::<u32>::new_uninit(); let five = unsafe { // Deferred initialization: five.as_mut(&Global).write(5); five.assume_init() }; assert_eq!(*five.as_ref(&Global), 5);
impl<T, B, D> Box<[MaybeUninit<T>], B, D> where
B: Buffer<[T], ExternalData = D> + Buffer<[MaybeUninit<T>], ExternalData = D>,
[src]
B: Buffer<[T], ExternalData = D> + Buffer<[MaybeUninit<T>], ExternalData = D>,
pub unsafe fn assume_init(self) -> Box<[T], B, D>
[src]
Constructs a boxed with uninitialized contents in the provided buffer.
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
use std::mem; use storages::boxed::Box; let buffer = [mem::MaybeUninit::<u32>::uninit(); 3]; let mut values = Box::new_uninit_slice_in(buffer, ()); let values = unsafe { // Deferred initialization: values[0].as_mut_ptr().write(1); values[1].as_mut_ptr().write(2); values[2].as_mut_ptr().write(3); values.assume_init() }; assert_eq!(*values, [1, 2, 3])
Trait Implementations
impl<T, U, D, BT, BU> CoerceUnsized<Box<U, BU, D>> for Box<T, BT, D> where
T: ?Sized,
U: ?Sized,
BT: Buffer<T, ExternalData = D> + CoerceUnsized<BU>,
BU: Buffer<U, ExternalData = D>,
[src]
T: ?Sized,
U: ?Sized,
BT: Buffer<T, ExternalData = D> + CoerceUnsized<BU>,
BU: Buffer<U, ExternalData = D>,
impl<T, B, D> Deref for Box<T, B, D> where
T: ?Sized,
B: Buffer<T, ExternalData = D>,
[src]
T: ?Sized,
B: Buffer<T, ExternalData = D>,
impl<T, B, D> DerefMut for Box<T, B, D> where
T: ?Sized,
B: Buffer<T, ExternalData = D>,
[src]
T: ?Sized,
B: Buffer<T, ExternalData = D>,
impl<T, S, D> Drop for Box<T, S, D> where
T: ?Sized,
S: UnmanagedBuffer<T, ExternalData = D>,
[src]
T: ?Sized,
S: UnmanagedBuffer<T, ExternalData = D>,
Auto Trait Implementations
impl<T: ?Sized, B, D> Send for Box<T, B, D> where
B: Send,
D: Send,
B: Send,
D: Send,
impl<T: ?Sized, B, D> Sync for Box<T, B, D> where
B: Sync,
D: Sync,
B: Sync,
D: Sync,
impl<T: ?Sized, B, D> Unpin for Box<T, B, D> where
B: Unpin,
D: Unpin,
B: Unpin,
D: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,