Skip to main content

Stable structures

Intermediate
Rust
Tutorial

Stable structures are a set of scalable data structures designed storing data and allowing it to grow to gigabytes in size without the need for pre_upgrade/post_upgrade hooks. Using pre_ and post_upgrade hooks is discouraged. It is error-prone and can render a canister unusable.

When a stable structure is initialized, memory is provided to the data structure. Each data structure manages is own memory and cannot share memories with other structures.

To use stable structures, the Rust stable structure library exists. It simplifies managing data structures directly in stable memory and provides example code templates. A brief example can be found below:

examples/src/basic_example/src/lib.rs
loading...

Available data structures

The stable structures library includes:

For more information about stable structures, please see the stable structures library and Roman's tutorial on stable structures.