Expand description
Stable memory allocator and related structs Various functions and data structures to organize and work with raw stable memory.
This crate provides a notion of “stable memory ownership”. This is a set of techniques, that
make data stored in stable memory appear like it gets automatically garbage collected by Rust’s borrower.
Each stable memory primitive includes a stable drop flag - a special flag, that is used by
Rust to understand, whether it should release stable memory, when it naturally drops the value,
or not.
Stable drop flag rules are simple:
- When you write something to stable memory, set its drop flag to
offposition. - When you read something from stable memory, and you don’t have an intention to move it,
set the drop flag to
offposition. - When you read something from stable memory with an intention to move this data somewhere else,
set the drop flag to
onposition. - When you Drop the value, if the drop flag is
on- call StableType::stable_drop, otherwise just Drop.
These rules are transparently managed at runtime. For users of this crate it appears like stable memory can “own” some value. A set of lifetimes applied later, on the data structure layer, to make it seem like the value is owned by a particular stable data structure.
If you’re thinking of implementing your own data structure using this crate, check this document for more info on this topic.
Modules§
- allocator
- Stable memory allocator used by every data collection in this crate.
- free_
block - A struct that is used by StableMemoryAllocator to represent a free block.
- s_slice
- A primitive smart-pointer that points to an allocated memory block.
Functions§
- clear⚠
- Wipes out stable memory, making it zero pages again.
- read_
bytes ⚠ - Reads raw bytes from stable memory.
- read_
fixed_ ⚠for_ move - Reads a StableType value that will move implementing AsFixedSizeBytes trait from stable memory.
- read_
fixed_ ⚠for_ reference - Reads a StableType value that won’t move implementing AsFixedSizeBytes trait from stable memory.
- write_
bytes ⚠ - Write raw bytes to stable memory.
- write_
fixed ⚠ - Writes a StableType value implementing AsFixedSizeBytes trait to stable memory.
Type Aliases§
- Stable
Ptr - A pointer to something is stable memory.