1use anyhow::Result;
2use serde::{de::DeserializeOwned, Serialize};
3
4#[cfg(not(target_arch = "wasm32"))]
5mod file;
6#[cfg(target_arch = "wasm32")]
7mod wasm;
8
9#[cfg(not(target_arch = "wasm32"))]
10type Store = file::FileStore;
11
12#[cfg(target_arch = "wasm32")]
13type Store = wasm::WasmStore;
14
15pub fn load<T: DeserializeOwned + Serialize>(key: &str, path: Option<&str>) -> Result<T> {
16 Store::load(key, path)
17}
18pub fn store<T: DeserializeOwned + Serialize>(key: &str, value: &T, path: Option<&str>) -> Result<()> {
19 Store::store(key, value, path)
20}
21pub fn load_raw(key: &str, path: Option<&str>) -> Result<Vec<u8>> {
22 Store::load_raw(key, path)
23}
24pub fn store_raw(key: &str, value: &[u8], path: Option<&str>) -> Result<()> {
25 Store::store_raw(key, value, path)
26}
27pub fn remove(key: &str, path: Option<&str>) -> Result<()> {
28 Store::remove(key, path)
29}
30
31trait KVStore {
32 fn load<T: DeserializeOwned + Serialize>(key: &str, path: Option<&str>) -> Result<T>;
33 fn store<T: DeserializeOwned + Serialize>(key: &str, value: &T, path: Option<&str>) -> Result<()>;
34 fn load_raw(key: &str, path: Option<&str>) -> Result<Vec<u8>>;
35 fn store_raw(key: &str, value: &[u8], path: Option<&str>) -> Result<()>;
36 fn remove(key: &str, path: Option<&str>) -> Result<()>;
37}