tauri_store/store/marshaler/
mod.rs

1mod json;
2
3#[cfg(feature = "marshaler-cbor")]
4mod cbor;
5#[cfg(feature = "marshaler-ron")]
6mod ron;
7#[cfg(feature = "marshaler-toml")]
8mod toml;
9
10use crate::store::StoreState;
11
12pub use json::{JsonMarshaler, PrettyJsonMarshaler};
13
14#[cfg(feature = "marshaler-cbor")]
15pub use cbor::CborMarshaler;
16#[cfg(feature = "marshaler-ron")]
17pub use ron::{PrettyRonMarshaler, RonMarshaler};
18#[cfg(feature = "marshaler-toml")]
19pub use toml::{PrettyTomlMarshaler, TomlMarshaler};
20
21/// Generic marshaling error.
22pub type MarshalingError = Box<dyn std::error::Error + Send + Sync>;
23
24/// Describes how stores should be serialized and deserialized.
25pub trait Marshaler: Send + Sync {
26  fn serialize(&self, state: &StoreState) -> Result<Vec<u8>, MarshalingError>;
27  fn deserialize(&self, bytes: &[u8]) -> Result<StoreState, MarshalingError>;
28
29  /// Extension with which the store will be saved. Defaults to `store`.
30  fn extension(&self) -> &'static str {
31    "store"
32  }
33}