Box

Struct Box 

Source
pub struct Box<T, A>
where A: Allocator,
{ /* private fields */ }
Expand description

A Müsli-allocated pointer type that uniquely owns a heap allocation of type T.

This is a Box type capable of using the allocator provided through a Context. Therefore it can be safely used in no-std environments.

Implementations§

Source§

impl<T, A> Box<T, A>
where A: Allocator,

Source

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> AsRef<T> for Box<T, A>
where A: Allocator,

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T, A> Clone for Box<T, A>
where T: Clone, A: GlobalAllocator,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, A> Debug for Box<T, A>
where T: Debug, A: Allocator,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, A> Deref for Box<T, A>
where A: Allocator,

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T, A> DerefMut for Box<T, A>
where A: Allocator,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T, A> Display for Box<T, A>
where T: Display, A: Allocator,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, A> Drop for Box<T, A>
where A: Allocator,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, A> Hash for Box<T, A>
where T: Hash, A: Allocator,

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, A> Hasher for Box<T, A>
where T: Hasher, A: Allocator,

Source§

fn finish(&self) -> u64

Returns the hash value for the values written so far. Read more
Source§

fn write(&mut self, bytes: &[u8])

Writes some data into this Hasher. Read more
Source§

fn write_u8(&mut self, i: u8)

Writes a single u8 into this hasher.
Source§

fn write_u16(&mut self, i: u16)

Writes a single u16 into this hasher.
Source§

fn write_u32(&mut self, i: u32)

Writes a single u32 into this hasher.
Source§

fn write_u64(&mut self, i: u64)

Writes a single u64 into this hasher.
Source§

fn write_u128(&mut self, i: u128)

Writes a single u128 into this hasher.
Source§

fn write_usize(&mut self, i: usize)

Writes a single usize into this hasher.
Source§

fn write_i8(&mut self, i: i8)

Writes a single i8 into this hasher.
Source§

fn write_i16(&mut self, i: i16)

Writes a single i16 into this hasher.
Source§

fn write_i32(&mut self, i: i32)

Writes a single i32 into this hasher.
Source§

fn write_i64(&mut self, i: i64)

Writes a single i64 into this hasher.
Source§

fn write_i128(&mut self, i: i128)

Writes a single i128 into this hasher.
Source§

fn write_isize(&mut self, i: isize)

Writes a single isize into this hasher.
Source§

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§

fn write_str(&mut self, s: &str)

🔬This is a nightly-only experimental API. (hasher_prefixfree_extras)
Writes a single str into this hasher. Read more
Source§

impl<T, A> Ord for Box<T, A>
where T: Ord, A: Allocator,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T, A> PartialEq for Box<T, A>
where T: PartialEq, A: Allocator,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &Self) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, A> PartialOrd for Box<T, A>
where T: PartialOrd, A: Allocator,

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
Source§

fn lt(&self, other: &Self) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
Source§

fn le(&self, other: &Self) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

fn ge(&self, other: &Self) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

fn gt(&self, other: &Self) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

impl<T, A> Eq for Box<T, A>
where T: Eq, A: Allocator,

Source§

impl<T, A> Send for Box<T, A>
where T: Send, A: Allocator,

Source§

impl<T, A> Sync for Box<T, A>
where T: Sync, A: Allocator,

Auto Trait Implementations§

§

impl<T, A> Freeze for Box<T, A>
where <A as Allocator>::Alloc<T>: Freeze,

§

impl<T, A> RefUnwindSafe for Box<T, A>
where <A as Allocator>::Alloc<T>: RefUnwindSafe,

§

impl<T, A> Unpin for Box<T, A>
where <A as Allocator>::Alloc<T>: Unpin,

§

impl<T, A> UnwindSafe for Box<T, A>
where <A as Allocator>::Alloc<T>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.