Skip to content

storage_slot - [devnet]

use 0x1::features;
use 0x1::object;
use 0x1::signer;

Constants

Storage slot natives are not enabled.

const ESTORAGE_SLOT_NATIVES_NOT_ENABLED: u64 = 1;

Resource under storage slot not found, this should never happen. Emitted by native functions.

const ESTORAGE_SLOT_NOT_FOUND: u64 = 2;

Structs

StorageSlot

struct StorageSlot<T> has store
Fields
addr: address

Resources

StorageSlotResource

struct StorageSlotResource<T> has key
Fields
val: T

Functions

new

public fun new<T: store>(value: T): storage_slot::StorageSlot<T>
Implementation
public fun new<T: store>(value: T): StorageSlot<T> {
let unique_signer = object::create_unique_onchain_signer().generate_signer_for_extending();
move_to(&unique_signer, StorageSlotResource { val: value });
StorageSlot { addr: unique_signer.address_of() }
}

borrow_storage_slot_resource

fun borrow_storage_slot_resource<T: store, BR>(self: &storage_slot::StorageSlot<T>): &BR
Implementation
native fun borrow_storage_slot_resource<T: store, BR>(self: &StorageSlot<T>): &BR;

borrow_storage_slot_resource_mut

fun borrow_storage_slot_resource_mut<T: store, BR>(self: &mut storage_slot::StorageSlot<T>): &mut BR
Implementation
native fun borrow_storage_slot_resource_mut<T: store, BR>(self: &mut StorageSlot<T>): &mut BR;

borrow

public fun borrow<T: store>(self: &storage_slot::StorageSlot<T>): &T
Implementation
public fun borrow<T: store>(self: &StorageSlot<T>): &T {
assert!(std::features::is_storage_slot_natives_enabled(), ESTORAGE_SLOT_NATIVES_NOT_ENABLED);
&self.borrow_storage_slot_resource<T, StorageSlotResource<T>>().val
}

borrow_mut

public fun borrow_mut<T: store>(self: &mut storage_slot::StorageSlot<T>): &mut T
Implementation
public fun borrow_mut<T: store>(self: &mut StorageSlot<T>): &mut T {
assert!(std::features::is_storage_slot_natives_enabled(), ESTORAGE_SLOT_NATIVES_NOT_ENABLED);
&mut self.borrow_storage_slot_resource_mut<T, StorageSlotResource<T>>().val
}

copy_storage_slot

public fun copy_storage_slot<T: copy, store>(self: &storage_slot::StorageSlot<T>): storage_slot::StorageSlot<T>
Implementation
public fun copy_storage_slot<T: store + copy>(self: &StorageSlot<T>): StorageSlot<T> {
new(*self.borrow())
}

destroy

public fun destroy<T: store>(self: storage_slot::StorageSlot<T>): T
Implementation
public fun destroy<T: store>(self: StorageSlot<T>): T {
let StorageSlot { addr } = self;
let StorageSlotResource { val } = move_from<StorageSlotResource<T>>(addr);
val
}

Specification

pragma verify = false;

new

public fun new<T: store>(value: T): storage_slot::StorageSlot<T>
pragma verify = false;

borrow

public fun borrow<T: store>(self: &storage_slot::StorageSlot<T>): &T
pragma opaque;
pragma verify = false;
aborts_if [abstract] false;

borrow_mut

public fun borrow_mut<T: store>(self: &mut storage_slot::StorageSlot<T>): &mut T
pragma opaque;
pragma verify = false;
aborts_if [abstract] false;

copy_storage_slot

public fun copy_storage_slot<T: copy, store>(self: &storage_slot::StorageSlot<T>): storage_slot::StorageSlot<T>
pragma verify = false;

destroy

public fun destroy<T: store>(self: storage_slot::StorageSlot<T>): T
pragma verify = false;