Struct Boxed

Source
#[repr(C)]
pub struct Boxed<'a, T: ?Sized + 'a, A: Allocator = PoolAlloc> { /* private fields */ }

Implementations§

Source§

impl<T> Boxed<'static, T, PoolAlloc>

Source

pub fn new(val: T) -> Result<Self>

Source§

impl Boxed<'static, (), PoolAlloc>

利用函数的泛型参数方便推导出Boxed<’a, T, A>的类型参数

Source

pub fn zeroed<T>() -> Result<Boxed<'static, MaybeUninit<T>, PoolAlloc>>

Source

pub fn uninit<T>() -> Result<Boxed<'static, MaybeUninit<T>, PoolAlloc>>

Source

pub fn zeroed_slice<T>( len: usize, ) -> Result<Boxed<'static, [MaybeUninit<T>], PoolAlloc>>

Source

pub fn uninit_slice<T>( len: usize, ) -> Result<Boxed<'static, [MaybeUninit<T>], PoolAlloc>>

Source

pub fn new_then<T, F>(f: F) -> Result<Boxed<'static, T, PoolAlloc>>
where F: FnOnce() -> Result<T>,

Source

pub fn new_slice_then<T, F>( len: usize, f: F, ) -> Result<Boxed<'static, [T], PoolAlloc>>
where F: FnMut(usize) -> Result<T>,

Source§

impl Boxed<'static, [u8], PoolAlloc>

Source

pub fn new_buf(layout: Layout) -> Result<Self>

Source

pub fn new_buf_then<F>(layout: Layout, f: F) -> Result<Self>
where F: FnOnce(NonNull<[u8]>) -> Result<()>,

Source§

impl<T> Boxed<'static, [T], PoolAlloc>

Source

pub fn new_slice(len: usize, val: T) -> Result<Self>
where T: Clone,

Source§

impl<'a, T, A: Allocator> Boxed<'a, T, A>

Source

pub fn new_in(alloc: &'a A, val: T) -> Result<Self>

Source§

impl<'a, A: Allocator> Boxed<'a, (), A>

Source

pub fn zeroed_in<T>(alloc: &'a A) -> Result<Boxed<'a, MaybeUninit<T>, A>>

Source

pub fn uninit_in<T>(alloc: &'a A) -> Result<Boxed<'a, MaybeUninit<T>, A>>

Source

pub fn zeroed_slice_in<T>( alloc: &'a A, len: usize, ) -> Result<Boxed<'a, [MaybeUninit<T>], A>>

Source

pub fn uninit_slice_in<T>( alloc: &'a A, len: usize, ) -> Result<Boxed<'a, [MaybeUninit<T>], A>>

Source

pub fn new_then_in<T, F>(alloc: &'a A, f: F) -> Result<Boxed<'a, T, A>>
where F: FnOnce() -> Result<T>,

Source

pub fn new_slice_then_in<T, F>( alloc: &'a A, len: usize, f: F, ) -> Result<Boxed<'a, [T], A>>
where F: FnMut(usize) -> Result<T>,

Source§

impl<'a, A: Allocator> Boxed<'a, [u8], A>

Source

pub fn new_buf_in(alloc: &'a A, layout: Layout) -> Result<Self>

Source

pub fn new_buf_then_in<F>(alloc: &'a A, layout: Layout, f: F) -> Result<Self>
where F: FnOnce(NonNull<[u8]>) -> Result<()>,

Source§

impl<'a, T, A: Allocator> Boxed<'a, [T], A>

Source

pub fn new_slice_in(alloc: &'a A, len: usize, val: T) -> Result<Self>
where T: Clone,

Source§

impl<'a, T> Boxed<'a, T, NullAlloc>

Source

pub unsafe fn from_raw(data: *mut T) -> Self

§Safety

使用者保证data一定是有效的非空指针, 其所有权转移给Boxed返回值 但是其申请的内存不会被释放 如果需要正常释放内存,应该调用Boxed::from_with

Source§

impl<T> Boxed<'_, [T], NullAlloc>

Source

pub unsafe fn from_raw_slice(data: *mut T, len: usize) -> Self

§Safety

data and len should be valid slice

Source§

impl<'a, T, A: Allocator> Boxed<'a, MaybeUninit<T>, A>

Source

pub fn write(self, val: T) -> Boxed<'a, T, A>

Source§

impl<'a, T, A: Allocator> Boxed<'a, [MaybeUninit<T>], A>

Source

pub fn write_slice_then<F>(self, f: F) -> Result<Boxed<'a, [T], A>>
where F: FnMut(usize) -> Result<T>,

Source§

impl<'a, T: ?Sized + 'a, A: Allocator> Boxed<'a, T, A>

Source

pub unsafe fn from_with(ptr: NonNull<T>, layout: Layout, alloc: &'a A) -> Self

§Safety

用户保证(ptr, layout, alloc)是Boxed::leak的返回值

Source

pub unsafe fn from_boxed(data: Boxed<'a, T, NullAlloc>, alloc: &'a A) -> Self

§Safety

用户保证data是leak_boxed的返回值, 且是从alloc分配的内存

Source

pub const fn as_ptr(&self) -> *mut T

Source

pub unsafe fn as_other<U>(&self) -> &U

§Safety

使用人员需要保证类型内存布局相同

Source

pub unsafe fn as_other_mut<U>(&mut self) -> &mut U

§Safety

使用人员需要保证类型内存布局相同

Source

pub unsafe fn as_slice<U>(&self, len: usize) -> &[U]

§Safety

使用人员需要保证转换后类型/长度的正确性

Source

pub unsafe fn as_slice_mut<U>(&mut self, len: usize) -> &mut [U]

§Safety

使用人员需要保证转换后类型/长度的正确性

Source

pub unsafe fn cast<U>(self) -> Result<Boxed<'a, U, A>, Self>

§Safety

使用人员需要保证U/T的内存布局相同

Source

pub unsafe fn cast_unchecked<U>(self) -> Boxed<'a, U, A>

§Safety

使用人员需要保证U/T的内存布局相同, 可用于从某个trait转为为具体实现类场景.

Source

pub unsafe fn cast_slice<U>(self, len: usize) -> Result<Boxed<'a, [U], A>, Self>

§Safety

使用人员需要保证U/T的内存布局相同

Source

pub unsafe fn cast_slice_unchecked<U>(self, len: usize) -> Boxed<'a, [U], A>

§Safety

使用人员需要保证U/T的内存布局相同

Source

pub fn leak(self) -> (&'a mut T, Layout, &'a A)

Source

pub fn leak_boxed(self) -> Boxed<'a, T, NullAlloc>

资源所有权转移,但是其内存不会被释放

Source§

impl<'a, T: Any, A: Allocator> Boxed<'a, T, A>

Source

pub fn to_any(self) -> Boxed<'a, dyn Any, A>

Source§

impl<'a, A: Allocator> Boxed<'a, dyn Any + 'a, A>

Source

pub fn downcast<T: Any>(self) -> Result<Boxed<'a, T, A>, Self>

Source§

impl<'a, T: ?Sized, A: Allocator> Boxed<'a, T, A>

Source

pub fn upcast<U: ?Sized>( self, f: impl FnOnce(&T) -> &U, ) -> Result<Boxed<'a, U, A>, Self>

用于实现到某个trait的转换.

Source§

impl<'a, T: ?Sized, A: Allocator> Boxed<'a, T, A>

Source

pub fn layout(&self) -> Layout

Trait Implementations§

Source§

impl<'a, T: ?Sized + Allocator, A: Allocator> Allocator for Boxed<'a, T, A>

Source§

unsafe fn free_buf(&self, ptr: NonNull<[u8]>, layout: Layout)

§Safety

ptr一定时alloc_buf分配的内存地址

Source§

unsafe fn alloc_buf<F>(&self, layout: Layout, f: F) -> Result<NonNull<[u8]>>
where F: FnOnce(NonNull<[u8]>) -> Result<()>,

Safety Read more
Source§

impl<T: ?Sized, A: Allocator> AsMut<T> for Boxed<'_, T, A>

Source§

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

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

impl<T: ?Sized, A: Allocator> AsRef<T> for Boxed<'_, T, A>

Source§

fn as_ref(&self) -> &T

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

impl<T: ?Sized + Debug, A: Allocator> Debug for Boxed<'_, T, A>

Source§

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

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

impl<T: ?Sized, A: Allocator> Deref for Boxed<'_, T, A>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T: ?Sized, A: Allocator> DerefMut for Boxed<'_, T, A>

Source§

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

Mutably dereferences the value.
Source§

impl<T: ?Sized + Display, A: Allocator> Display for Boxed<'_, T, A>

Source§

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

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

impl<T: ?Sized, A: Allocator> Drop for Boxed<'_, T, A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: ?Sized + Hash, A: Allocator> Hash for Boxed<'_, T, A>

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: ?Sized + Hasher, A: Allocator> Hasher for Boxed<'_, T, A>

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, data: u8)

Writes a single u8 into this hasher.
Source§

fn write_u16(&mut self, data: u16)

Writes a single u16 into this hasher.
Source§

fn write_u32(&mut self, data: u32)

Writes a single u32 into this hasher.
Source§

fn write_u64(&mut self, data: u64)

Writes a single u64 into this hasher.
Source§

fn write_u128(&mut self, data: u128)

Writes a single u128 into this hasher.
Source§

fn write_usize(&mut self, data: usize)

Writes a single usize into this hasher.
Source§

fn write_isize(&mut self, data: isize)

Writes a single isize into this hasher.
Source§

fn write_i8(&mut self, data: i8)

Writes a single i8 into this hasher.
Source§

fn write_i16(&mut self, data: i16)

Writes a single i16 into this hasher.
Source§

fn write_i32(&mut self, data: i32)

Writes a single i32 into this hasher.
Source§

fn write_i64(&mut self, data: i64)

Writes a single i64 into this hasher.
Source§

fn write_i128(&mut self, data: i128)

Writes a single i128 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: ?Sized + Ord, A: Allocator> Ord for Boxed<'_, T, A>

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: ?Sized + PartialEq, A: Allocator> PartialEq for Boxed<'_, T, A>

Source§

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

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

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

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

impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Boxed<'_, T, A>

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 gt(&self, other: &Self) -> bool

Tests greater than (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§

impl<T: ?Sized, A: Allocator> Pointer for Boxed<'_, T, A>

Source§

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

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

impl<T: ?Sized + Eq, A: Allocator> Eq for Boxed<'_, T, A>

Source§

impl<T: ?Sized + Allocator + Pool, A: Allocator> Pool for Boxed<'_, T, A>

Source§

impl<T: ?Sized + Send, A: Allocator + Pool> Send for Boxed<'static, T, A>

Source§

impl<T: ?Sized + Sync, A: Allocator> Sync for Boxed<'static, T, A>

Source§

impl<T: ?Sized + Unpin, A: Allocator> Unpin for Boxed<'_, T, A>

Auto Trait Implementations§

§

impl<'a, T, A> Freeze for Boxed<'a, T, A>
where T: ?Sized,

§

impl<'a, T, A> RefUnwindSafe for Boxed<'a, T, A>

§

impl<'a, T, A> UnwindSafe for Boxed<'a, T, A>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A> GenericAlloc for A
where A: Allocator + ?Sized,

Source§

unsafe fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, Error>

Safety Read more
Source§

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)

Safety Read more
Source§

unsafe fn init<T>(&self, val: T) -> Result<NonNull<T>, Error>

Safety Read more
Source§

unsafe fn alloc_then<T, F>(&self, f: F) -> Result<NonNull<T>, Error>
where F: FnOnce() -> Result<T, Error>,

Safety Read more
Source§

unsafe fn init_slice<T>( &self, len: usize, val: T, ) -> Result<NonNull<[T]>, Error>
where T: Clone,

Safety Read more
Source§

unsafe fn alloc_slice_then<T, F>( &self, len: usize, f: F, ) -> Result<NonNull<[T]>, Error>
where F: FnMut(usize) -> Result<T, Error>,

Safety Read more
Source§

unsafe fn zeroed<T>(&self) -> Result<NonNull<MaybeUninit<T>>, Error>

Safety Read more
Source§

unsafe fn zeroed_slice<T>( &self, len: usize, ) -> Result<NonNull<[MaybeUninit<T>]>, Error>

Safety Read more
Source§

unsafe fn uninit<T>(&self) -> Result<NonNull<MaybeUninit<T>>, Error>

Safety Read more
Source§

unsafe fn uninit_slice<T>( &self, len: usize, ) -> Result<NonNull<[MaybeUninit<T>]>, Error>

Safety Read more
Source§

unsafe fn release<T>(&self, ptr: NonNull<T>)

Safety Read more
Source§

unsafe fn release_with<T>(&self, ptr: NonNull<T>, layout: Layout)
where T: ?Sized,

Safety Read more
Source§

unsafe fn release_slice<T>(&self, ptr: NonNull<[T]>)

Safety Read more
Source§

unsafe fn release_slice_with<T>(&self, ptr: NonNull<[T]>, layout: Layout)

Safety Read more
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, 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.