zink/storage/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Zink storage implementation.

use crate::{ffi, Asm};
pub use {
    dkmapping::{DoubleKeyMapping, DoubleKeyTransientMapping},
    mapping::{Mapping, TransientMapping},
    value::{Storage, TransientStorage},
};

mod dkmapping;
mod mapping;
mod value;

/// Interface for the value of kv based storage
pub trait StorageValue: Asm {
    /// Load from storage
    fn sload() -> Self;
}

/// Interface for the value of kv based transient storage
pub trait TransientStorageValue: Asm {
    /// Load from transient storage
    fn tload() -> Self;
}

impl StorageValue for i32 {
    fn sload() -> Self {
        unsafe { ffi::asm::sload_i32() }
    }
}

impl StorageValue for u32 {
    fn sload() -> Self {
        unsafe { ffi::asm::sload_u32() }
    }
}

impl TransientStorageValue for i32 {
    fn tload() -> Self {
        unsafe { ffi::asm::tload_i32() }
    }
}

impl TransientStorageValue for u32 {
    fn tload() -> Self {
        unsafe { ffi::asm::tload_u32() }
    }
}