Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Module 0x1::storage_slot_or_inline

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

Struct Dummy

struct Dummy has store
Fields
dummy_field: bool

Constants

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

const ESTORAGE_SLOT_INCORRECTLY_IN_TRANSIENT_STATE: u64 = 1;

Function 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 }
}

Function 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) }
}

Function 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,
    }
}

Function 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,
    }
}

Function 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,
    }
}

Function 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,
    }
}

Function 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;