Struct ic_stable_structures::cell::Cell
source · pub struct Cell<T: Storable, M: Memory> { /* private fields */ }
Expand description
Represents a serializable value stored in the stable memory. It has semantics similar to “stable variables” in Motoko and share the same limitations. The main difference is that Cell writes its value to the memory on each assignment, not just in upgrade hooks. You should use cells only for small (up to a few MiB) values to keep upgrades safe.
Cell is a good choice for small read-only configuration values set once on canister installation and rarely updated.
Implementations§
source§impl<T: Storable, M: Memory> Cell<T, M>
impl<T: Storable, M: Memory> Cell<T, M>
sourcepub fn new(memory: M, value: T) -> Result<Self, ValueError>
pub fn new(memory: M, value: T) -> Result<Self, ValueError>
Creates a new cell in the specified memory, overwriting the previous contents of the memory.
sourcepub fn init(memory: M, default_value: T) -> Result<Self, InitError>
pub fn init(memory: M, default_value: T) -> Result<Self, InitError>
Initializes the value of the cell based on the contents of the memory
.
If the memory already contains a cell, initializes the cell with the decoded value.
Otherwise, sets the cell value to default_value
and writes it to the memory.
sourcepub fn into_memory(self) -> M
pub fn into_memory(self) -> M
Returns the underlying memory.
sourcepub fn set(&mut self, value: T) -> Result<T, ValueError>
pub fn set(&mut self, value: T) -> Result<T, ValueError>
Updates the current value in the cell. If the new value is too large to fit into the memory, the value in the cell does not change.