Skip to main content

PlatformStorage

Trait PlatformStorage 

Source
pub trait PlatformStorage {
    // Required methods
    fn storage_get(&self, key: &str) -> Option<String>;
    fn storage_set(
        &mut self,
        key: &str,
        value: &str,
    ) -> Result<(), PlatformError>;
    fn storage_remove(&mut self, key: &str) -> Result<(), PlatformError>;
    fn storage_clear(&mut self) -> Result<(), PlatformError>;
}
Expand description

Unified key-value local storage contract shared across Web, Mobile, HarmonyOS, Wearables, Mini-Programs, and QuickApps.

Required Methods§

Source

fn storage_get(&self, key: &str) -> Option<String>

Reads a UTF-8 value associated with key from sandboxed local storage.

§Arguments
  • &Self - Storage adapter reference.
  • &str - Storage key.
§Returns
  • Option<String> - Stored value, if present.
Source

fn storage_set(&mut self, key: &str, value: &str) -> Result<(), PlatformError>

Stores a UTF-8 value under key in sandboxed local storage.

§Arguments
  • &Self - Mutable storage adapter.
  • &str - Storage key.
  • &str - UTF-8 value to persist.
§Returns
  • Result<(), PlatformError> - Persistence status.
Source

fn storage_remove(&mut self, key: &str) -> Result<(), PlatformError>

Removes key from sandboxed local storage.

§Arguments
  • &Self - Mutable storage adapter.
  • &str - Storage key to remove.
§Returns
  • Result<(), PlatformError> - Removal status.
Source

fn storage_clear(&mut self) -> Result<(), PlatformError>

Clears all keys from sandboxed local storage.

§Arguments
  • &Self - Mutable storage adapter.
§Returns
  • Result<(), PlatformError> - Clear status.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl PlatformStorage for HarmonyPlatform

PlatformStorage implementation for HarmonyPlatform.

Source§

impl PlatformStorage for MiniAppPlatform

PlatformStorage implementation for MiniAppPlatform.

Source§

impl PlatformStorage for QuickAppPlatform

PlatformStorage implementation backed by @system.storage commands.

Source§

impl PlatformStorage for TerminalPlatform

PlatformStorage implementation for TerminalPlatform.

Source§

impl PlatformStorage for WearablePlatform

PlatformStorage implementation for WearablePlatform.