1use crate::prelude::*;
4
5#[derive(Debug, Error)]
7pub enum PersistenceError {
8 #[cfg(not(target_family = "wasm"))]
9 #[error("{0}")]
10 Filesystem(
11 #[from]
12 #[source]
13 std::io::Error,
14 ),
15
16 #[cfg(target_family = "wasm")]
17 #[error("{0}")]
18 Browser(
19 #[from]
20 #[source]
21 gloo_storage::errors::StorageError,
22 ),
23
24 #[cfg(any(
25 feature = "ini",
26 feature = "json",
27 feature = "ron",
28 feature = "toml",
29 feature = "yaml"
30 ))]
31 #[error("{0}")]
32 Encoding(
33 #[from]
34 #[source]
35 std::str::Utf8Error,
36 ),
37
38 #[cfg(feature = "bincode")]
39 #[error("{0}")]
40 BincodeDeserialization(#[source] bincode::Error),
41 #[cfg(feature = "bincode")]
42 #[error("{0}")]
43 BincodeSerialization(#[source] bincode::Error),
44
45 #[cfg(feature = "ini")]
46 #[error("{0}")]
47 IniDeserialization(#[source] serde_ini::de::Error),
48 #[cfg(feature = "ini")]
49 #[error("{0}")]
50 IniSerialization(#[source] serde_ini::ser::Error),
51
52 #[cfg(feature = "json")]
53 #[error("{0}")]
54 JsonDeserialization(#[source] serde_json::Error),
55 #[cfg(feature = "json")]
56 #[error("{0}")]
57 JsonSerialization(#[source] serde_json::Error),
58
59 #[cfg(feature = "ron")]
60 #[error("{0}")]
61 RonDeserialization(#[source] ron::Error),
62 #[cfg(feature = "ron")]
63 #[error("{0}")]
64 RonSerialization(#[source] ron::Error),
65
66 #[cfg(feature = "toml")]
67 #[error("{0}")]
68 TomlDeserialization(#[source] toml::de::Error),
69 #[cfg(feature = "toml")]
70 #[error("{0}")]
71 TomlSerialization(#[source] toml::ser::Error),
72
73 #[cfg(feature = "yaml")]
74 #[error("{0}")]
75 YamlDeserialization(#[source] serde_yaml::Error),
76 #[cfg(feature = "yaml")]
77 #[error("{0}")]
78 YamlSerialization(#[source] serde_yaml::Error),
79}
80
81impl PersistenceError {
82 pub fn is_serde(&self) -> bool {
83 match self {
84 #[cfg(not(target_family = "wasm"))]
85 PersistenceError::Filesystem(_) => false,
86 #[cfg(target_family = "wasm")]
87 PersistenceError::Browser(error) => {
88 matches!(error, gloo_storage::errors::StorageError::SerdeError(_))
89 },
90
91 #[cfg(any(
92 feature = "bincode",
93 feature = "ini",
94 feature = "json",
95 feature = "ron",
96 feature = "toml",
97 feature = "yaml",
98 ))]
99 _ => true,
100 }
101 }
102}