Small Working Example of Rust's Stable Structures

We are currently working on simulating a directory structure, with directories, file metadata, and content inside of them.

We started working with Motoko Hashmaps, and we have done some progress but I would really like to avoid the pre-upgrade and post-upgrade calls.

Could anyone share some working code of Rust Stable Structures, it would help us understand them better. Thanks!

P.S. This is the link to the IC’s Stable Structures in Rust:

1 Like

Do you mean other examples than those already provided in the stable-structures repo?

Indeed David, those examples are just a template, and a very small example.

Not a real small app of any kind, like for a example a TODO app or a small recipe app, something that actually would benefit from the stable data structures and has now the advantage of not needing the pre-upgrade and post-upgrade calls for data persistence.

In that case you for example, maybe, have a look to Internet Identity and the Bitcoin canisters repo. They both use the stable structures. Hope that helps.

1 Like

Yes, that will help David, much appreciated.


There are also stable (in terms of using stable memory directly) BTrees in Motoko. Not sure though you well tested/maintained this library is @sardariuss

The library is currently getting a small rework, I will update soon the post about it.

1 Like

Also you might want to consider using the ic-wasi-polyfill and compiling to wasm32-wasi, if I’m not mistaken you get a file-system for free, either in memory or stable.

I wouldn’t consider implementing one from scratch.



That is a mouth full of information, is there anywhere that I can research this topic? No idea now how to do the steps you mentioned.


Implement Wasi: Introducing WASI for IC

1 Like

Then you should just have a file system, no need to implement one. It can be in memory on the heap or in stable memory


Thanks Jordan I will read the forum post.