Skip to content

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 may 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) -> i32 {
  let value = app
    .pinia()
    .get("store", "counter")
    .unwrap();

  serde_json::from_value(value).unwrap()
}

You can also use the try_get method to get the value directly as the desired type.

rust
#[tauri::command]
async fn try_get_counter(app: AppHandle) -> i32 {
  app
    .pinia()
    .try_get::<i32>("store", "counter")
    .unwrap()
}