tauri_store/store/marshaler/
json.rs1use super::{Marshaler, MarshalingError};
2use crate::store::StoreState;
3
4pub struct JsonMarshaler;
6
7impl Marshaler for JsonMarshaler {
8 fn serialize(&self, state: &StoreState) -> Result<Vec<u8>, MarshalingError> {
9 Ok(serde_json::to_vec(state)?)
10 }
11
12 fn deserialize(&self, bytes: &[u8]) -> Result<StoreState, MarshalingError> {
13 Ok(serde_json::from_slice(bytes)?)
14 }
15
16 fn extension(&self) -> &'static str {
17 "json"
18 }
19}
20
21pub struct PrettyJsonMarshaler;
23
24impl Marshaler for PrettyJsonMarshaler {
25 fn serialize(&self, state: &StoreState) -> Result<Vec<u8>, MarshalingError> {
26 Ok(serde_json::to_vec_pretty(state)?)
27 }
28
29 fn deserialize(&self, bytes: &[u8]) -> Result<StoreState, MarshalingError> {
30 Ok(serde_json::from_slice(bytes)?)
31 }
32
33 fn extension(&self) -> &'static str {
34 "json"
35 }
36}