Rust canister global state for stable structures without thread local storage and refcells?

Is it possible?

This would make code for defining and accessing stable structures much simpler

Strictly speaking, you don’t need to use thread_local. You can use other alternatives like the lazy_static crate, for instance. However, that won’t be any simpler, so between the choices out there I’d suggest sticking with thread_local.

Unfortunately there is no other way that I’m aware of to be able to declare global mutable variables in Rust that would be simpler. This blog post discusses the alternatives and why thread_local is the best option.

3 Likes