pub struct StableCell<T: Storable, M: Memory = DefaultMemoryImpl> { /* private fields */ }Expand description
StableCell
Governed upstream Cell with explicit initialization and read-only loading.
Values and stored bytes retain the upstream codec and layout contracts.
Implementations§
Source§impl<T: Storable, M: Memory> StableCell<T, M>
impl<T: Storable, M: Memory> StableCell<T, M>
Sourcepub fn create(memory: RuntimeMemory<M>, value: T) -> Self
pub fn create(memory: RuntimeMemory<M>, value: T) -> Self
Create a cell only in zero-page memory, enforcing declared record bounds.
§Panics
Refuses nonempty memory or a value outside its declared bound before writing. Growth and codec failures retain upstream behavior.
Sourcepub fn reset(memory: RuntimeMemory<M>, value: T) -> Self
pub fn reset(memory: RuntimeMemory<M>, value: T) -> Self
Deliberately replace any contents, enforcing the record’s declared bound.
§Panics
Refuses oversized/fixed-width mismatches before writing. Growth and codec failures retain upstream behavior. Unbounded record types remain allowed.
Sourcepub fn load(memory: RuntimeMemory<M>) -> Result<Self, StableCellPayloadError>
pub fn load(memory: RuntimeMemory<M>) -> Result<Self, StableCellPayloadError>
Load an existing cell without initializing, writing or growing memory.
Requires no default value or Default/Clone bound. The retained value
is decoded by upstream using T::from_bytes. A successful load retains
the allocation’s exclusive lease until this cell is dropped.
§Errors
Returns ic_memory::StableCellPayloadError for empty/foreign memory,
unsupported layout versions, a payload beyond memory or the declared maximum. The
consumed lease is released on failure; no bytes are changed.
§Panics
Codec and backing failures propagate as upstream panics. Loading does not write or grow even on these failures. Ordinary unwinding releases the consumed lease; Wasm traps retain the host’s rollback semantics. This validates the envelope, not the application’s schema or recovery policy.