The storage module provides asynchronous, type-safe bindings to the chrome.storage.local API. It uses serde for automatic serialization and deserialization of Rust types to and from JavaScript values. This allows you to store complex structs and enums directly in the browser's local storage.
// Example: Storing and retrieving a custom struct
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
struct UserSettings {
theme: String,
font_size: u32,
}
async fn manage_settings() -> oxichrome::Result<()> {
let settings = UserSettings {
theme: "dark".to_string(),
font_size: 14,
};
// Save to storage
storage::set("user_prefs", &settings).await?;
// Retrieve from storage
if let Some(retrieved) = storage::get::<UserSettings>("user_prefs").await? {
println!("Loaded settings: {:?}", retrieved);
}
// Remove from storage
storage::remove("user_prefs").await?;
Ok(())
}