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

Creates a new cell in the specified memory, overwriting the previous contents of the memory.

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.

Returns the current value in the cell.

Forgets the value in this cell and returns the underlying memory.

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.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.