Skip to main content

InitStorage

Struct InitStorage 

Source
pub struct InitStorage<T> { /* private fields */ }
Expand description

可消费的普通初始化存储。 Consumable storage for movable initialization.

初始化成功后会交付拥有型 InitValue;失败时错误返回给调用方,尚未初始化的存储随容器释放。 Success yields an owning InitValue; on failure, the error is returned and the uninitialized storage is released with the container.

Implementations§

Source§

impl<T> InitStorage<T>

Source

pub const fn uninit() -> Self

创建尚未初始化的拥有型存储。 Create owned storage that does not yet contain a T.

Source

pub fn initialize<I, E>(self, initializer: I) -> Result<InitValue<T>, E>
where I: Init<T, E>,

消耗未初始化存储,并尝试返回拥有初始化值的对象。 Consume the uninitialized storage and try to return an object that owns the initialized value.

错误不会产生 InitValue;若初始化器失败,调用方只会收到其错误值。 No InitValue is produced on error; if the initializer fails, the caller receives its error value. 该错误路径依赖 Init 的 unsafe 契约:返回错误或 panic 时,存储必须保持未初始化。 The error path relies on Init’s unsafe contract that storage remains uninitialized on error or panic.

Source

pub fn initialize_default(self) -> InitValue<T>
where T: InitDefault<T, InitMode>,

在存储槽位中构造默认值并返回拥有该值的对象。 Construct the default value in the storage slot and return an object that owns it.

Source

pub fn initialize_default_with<I>(self) -> InitValue<T>
where I: InitDefault<T, InitMode>,

使用指定的默认值提供者在存储槽位中构造目标。 Construct the target in the storage slot using the specified default-value provider.

I 可以与 T 不同,只要它实现了针对 T 和普通地址模式的 InitDefault。 I may differ from T as long as it implements InitDefault for T in movable mode.

Auto Trait Implementations§

§

impl<T> Freeze for InitStorage<T>
where MaybeUninit<T>: Freeze,

§

impl<T> RefUnwindSafe for InitStorage<T>

§

impl<T> Send for InitStorage<T>
where MaybeUninit<T>: Send,

§

impl<T> Sync for InitStorage<T>
where MaybeUninit<T>: Sync,

§

impl<T> Unpin for InitStorage<T>
where MaybeUninit<T>: Unpin,

§

impl<T> UnsafeUnpin for InitStorage<T>

§

impl<T> UnwindSafe for InitStorage<T>

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<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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.