aimdb_persistence/
error.rs1use core::fmt;
4
5#[derive(Debug)]
7pub enum PersistenceError {
8 NotConfigured,
12
13 BackendShutdown,
15
16 Backend(String),
18
19 Serialization(String),
21}
22
23impl fmt::Display for PersistenceError {
24 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 match self {
26 PersistenceError::NotConfigured => {
27 write!(
28 f,
29 "persistence backend not configured (call .with_persistence() on the builder)"
30 )
31 }
32 PersistenceError::BackendShutdown => {
33 write!(f, "persistence backend has shut down")
34 }
35 PersistenceError::Backend(msg) => write!(f, "persistence backend error: {}", msg),
36 PersistenceError::Serialization(msg) => {
37 write!(f, "persistence serialization error: {}", msg)
38 }
39 }
40 }
41}
42
43impl std::error::Error for PersistenceError {}
44
45impl From<serde_json::Error> for PersistenceError {
46 fn from(e: serde_json::Error) -> Self {
47 PersistenceError::Serialization(e.to_string())
48 }
49}