Accessing from Rust
When the ManagerExt
trait is in scope, you can access your stores from any type that implements the Manager trait (e.g. AppHandle
, Window
, WebviewWindow
).
Note that all values are stored as serde_json::Value
, so you will need to convert them to the desired type when accessing from Rust. You can check the serde_json documentation for more information.
A list of all available methods for the stores can be found here.
rust
use tauri_plugin_pinia::ManagerExt;
#[tauri::command]
async fn get_counter(app: AppHandle) -> Option<String> {
app
.with_store("store", |store| {
let counter = store
.get("counter")
.and_then(|it| it.as_str())
.map(ToOwned::to_owned);
Ok(counter)
})
.unwrap()
}