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 new(memory: RuntimeMemory<M>, value: T) -> Self
pub fn new(memory: RuntimeMemory<M>, value: T) -> Self
Create a new collection, replacing any prior collection in the selected memory. This is destructive even when a valid collection already exists.
§Panics
Panics on insufficient memory or codec/backing failure.
Sourcepub fn init(memory: RuntimeMemory<M>, default_value: T) -> Self
pub fn init(memory: RuntimeMemory<M>, default_value: T) -> Self
Open a recognized retained collection; initialize a new one when memory is empty or has foreign magic. Foreign contents may be overwritten. This is not a corruption-recovery or schema-admission operation.
§Panics
Panics for unsupported recognized layouts, invalid retained contents, insufficient memory or codec/backing failure.
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 or a payload extending beyond memory. 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.