pub struct Box<T, A>where
A: Allocator,{ /* private fields */ }Expand description
Implementations§
Source§impl<T, A> Box<T, A>where
A: Allocator,
impl<T, A> Box<T, A>where
A: Allocator,
Sourcepub fn new_in(value: T, alloc: A) -> Result<Self, AllocError>
pub fn new_in(value: T, alloc: A) -> Result<Self, AllocError>
Allocates memory on the heap and then places x into it.
This doesn’t actually allocate if T is zero-sized.
§Examples
use musli::alloc::{AllocError, Box};
musli::alloc::default(|alloc| {
let mut a = Box::new_in(10u32, alloc)?;
assert_eq!(a.as_ref(), &10u32);
Ok::<_, AllocError>(())
});Zero-sized types:
use musli::alloc::{AllocError, Box};
musli::alloc::default(|alloc| {
let mut a = Box::new_in((), alloc)?;
assert_eq!(a.as_ref(), &());
Ok::<_, AllocError>(())
});Trait Implementations§
Source§impl<T, A> Hasher for Box<T, A>
impl<T, A> Hasher for Box<T, A>
Source§fn write_u128(&mut self, i: u128)
fn write_u128(&mut self, i: u128)
Writes a single
u128 into this hasher.Source§fn write_usize(&mut self, i: usize)
fn write_usize(&mut self, i: usize)
Writes a single
usize into this hasher.Source§fn write_i128(&mut self, i: i128)
fn write_i128(&mut self, i: i128)
Writes a single
i128 into this hasher.Source§fn write_isize(&mut self, i: isize)
fn write_isize(&mut self, i: isize)
Writes a single
isize into this hasher.Source§fn write_length_prefix(&mut self, len: usize)
fn write_length_prefix(&mut self, len: usize)
🔬This is a nightly-only experimental API. (
hasher_prefixfree_extras)Writes a length prefix into this hasher, as part of being prefix-free. Read more
Source§impl<T, A> Ord for Box<T, A>
impl<T, A> Ord for Box<T, A>
Source§impl<T, A> PartialOrd for Box<T, A>where
T: PartialOrd,
A: Allocator,
impl<T, A> PartialOrd for Box<T, A>where
T: PartialOrd,
A: Allocator,
impl<T, A> Eq for Box<T, A>
impl<T, A> Send for Box<T, A>
impl<T, A> Sync for Box<T, A>
Auto Trait Implementations§
impl<T, A> Freeze for Box<T, A>
impl<T, A> RefUnwindSafe for Box<T, A>
impl<T, A> Unpin for Box<T, A>
impl<T, A> UnwindSafe for Box<T, A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more