跳转到内容

storage_slot_or_inline - [devnet]

此内容尚不支持你的语言。

use 0x1::mem;
use 0x1::storage_slot;

Enum StorageSlotOrInline

enum StorageSlotOrInline<T> has store
Variants
Inline
Fields
value: T
StorageSlot
Fields
slot: storage_slot::StorageSlot<T>
Transient
Fields

Constants

StorageSlotOrInline found in inconsistent (transient) state, should never happen.

const ESTORAGE_SLOT_INCORRECTLY_IN_TRANSIENT_STATE: u64 = 1;

Structs

Dummy

struct Dummy has store
Fields
dummy_field: bool

Functions

new_inline

public fun new_inline<T: store>(value: T): storage_slot_or_inline::StorageSlotOrInline<T>
Implementation
public fun new_inline<T: store>(value: T): StorageSlotOrInline<T> {
StorageSlotOrInline::Inline { value }
}

new_storage_slot

public fun new_storage_slot<T: store>(value: T): storage_slot_or_inline::StorageSlotOrInline<T>
Implementation
public fun new_storage_slot<T: store>(value: T): StorageSlotOrInline<T> {
StorageSlotOrInline::StorageSlot { slot: storage_slot::new(value) }
}

borrow

public fun borrow<T: store>(self: &storage_slot_or_inline::StorageSlotOrInline<T>): &T
Implementation
public fun borrow<T: store>(self: &StorageSlotOrInline<T>): &T {
match (self) {
StorageSlotOrInline::Inline { value } => value,
StorageSlotOrInline::StorageSlot { slot } => slot.borrow(),
StorageSlotOrInline::Transient => abort ESTORAGE_SLOT_INCORRECTLY_IN_TRANSIENT_STATE,
}
}

borrow_mut

public fun borrow_mut<T: store>(self: &mut storage_slot_or_inline::StorageSlotOrInline<T>): &mut T
Implementation
public fun borrow_mut<T: store>(self: &mut StorageSlotOrInline<T>): &mut T {
match (self) {
StorageSlotOrInline::Inline { value } => value,
StorageSlotOrInline::StorageSlot { slot } => slot.borrow_mut(),
StorageSlotOrInline::Transient => abort ESTORAGE_SLOT_INCORRECTLY_IN_TRANSIENT_STATE,
}
}

destroy

public fun destroy<T: store>(self: storage_slot_or_inline::StorageSlotOrInline<T>): T
Implementation
public fun destroy<T: store>(self: StorageSlotOrInline<T>): T {
match (self) {
StorageSlotOrInline::Inline { value } => value,
StorageSlotOrInline::StorageSlot { slot } => slot.destroy(),
StorageSlotOrInline::Transient => abort ESTORAGE_SLOT_INCORRECTLY_IN_TRANSIENT_STATE,
}
}

move_to_inline

public fun move_to_inline<T: store>(self: &mut storage_slot_or_inline::StorageSlotOrInline<T>)
Implementation
public fun move_to_inline<T: store>(self: &mut StorageSlotOrInline<T>) {
match (self) {
StorageSlotOrInline::Inline { value: _ } => {},
StorageSlotOrInline::StorageSlot { slot: _ } => {
let StorageSlotOrInline::StorageSlot { slot } = mem::replace(self, StorageSlotOrInline::Transient);
let StorageSlotOrInline::Transient = mem::replace(self, new_inline(slot.destroy()));
},
StorageSlotOrInline::Transient => abort ESTORAGE_SLOT_INCORRECTLY_IN_TRANSIENT_STATE,
}
}

move_to_storage_slot

public fun move_to_storage_slot<T: store>(self: &mut storage_slot_or_inline::StorageSlotOrInline<T>)
Implementation
public fun move_to_storage_slot<T: store>(self: &mut StorageSlotOrInline<T>) {
match (self) {
StorageSlotOrInline::Inline { value: _ } => {
let StorageSlotOrInline::Inline { value } = mem::replace(self, StorageSlotOrInline::Transient);
let StorageSlotOrInline::Transient = mem::replace(self, new_storage_slot(value));
},
StorageSlotOrInline::StorageSlot { slot: _ } => {},
StorageSlotOrInline::Transient => abort ESTORAGE_SLOT_INCORRECTLY_IN_TRANSIENT_STATE,
}
}

Specification

pragma verify = false;