Persistent Storage in Shuttle
Learn about Shuttle’s persistent storage solutions for Rust applications. Our docs explain how to maintain data persistently and efficiently.
The persist plugin allows anything that implements serde::Serialize
and serde::Deserialize
to be persisted in a key-value store on the filesystem, and persist between deployments. This is useful for saving and retrieving data when it is not desired to hard code that data into the app. An example is saved settings for a Discord bot that need to remain the same between updates. State data, used in web frameworks such as Axum and Rocket, is also a good candidate for use of the persist plugin.
Usage
To use the persist plugin, add shuttle-persist
to the dependencies of your service with cargo add shuttle-persist
. Then, annotate your shuttle_runtime::main
function by adding the shuttle-persist::Persist
attribute as a parameter. This will give a PersistInstance
. The methods available are:
save()
: saves a key-value pairload()
: loads the value stored in a keyremove()
: deletes a keylist()
: returns all the keys as a vector of stringsclear()
: deletes all keys
Example
This snippet shows a Shuttle rocket main function that uses the shuttle_persist::Persist
attribute to provision and get access to a PersistInstance
. In this example, the PersistInstance
is used to store state for the app.
The full example can be found on GitHub.
Was this page helpful?