tauri_store/store/marshaler/
ron.rs1use super::{Marshaler, MarshalingError};
2use crate::store::StoreState;
3use ron::de::from_bytes;
4use ron::ser::{to_string, to_string_pretty, PrettyConfig};
5
6pub struct RonMarshaler;
8
9impl Marshaler for RonMarshaler {
10 fn serialize(&self, state: &StoreState) -> Result<Vec<u8>, MarshalingError> {
11 Ok(to_string(state)?.into_bytes())
12 }
13
14 fn deserialize(&self, bytes: &[u8]) -> Result<StoreState, MarshalingError> {
15 Ok(from_bytes(bytes)?)
16 }
17
18 fn extension(&self) -> &'static str {
19 "ron"
20 }
21}
22
23pub struct PrettyRonMarshaler;
25
26impl Marshaler for PrettyRonMarshaler {
27 fn serialize(&self, state: &StoreState) -> Result<Vec<u8>, MarshalingError> {
28 let config = PrettyConfig::default();
29 Ok(to_string_pretty(state, config)?.into_bytes())
30 }
31
32 fn deserialize(&self, bytes: &[u8]) -> Result<StoreState, MarshalingError> {
33 Ok(from_bytes(bytes)?)
34 }
35
36 fn extension(&self) -> &'static str {
37 "ron"
38 }
39}