1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::{io, result};
use err_derive::Error;
use uuid::Uuid;
use crate::{serializer, storage};
#[derive(Debug, Error)]
pub enum Error {
#[error(display = "entity not found: {}", _0)]
NotFound(Uuid),
#[error(display = "bad format: {}", _0)]
Format(String),
#[error(display = "io error: {}", _0)]
Io(#[error(source)] io::Error),
#[error(display = "entity doesn't have an id")]
Unidentified,
}
impl From<storage::Error> for Error {
fn from(error: storage::Error) -> Self {
match error {
storage::Error::NotFound(e) => Self::NotFound(e),
storage::Error::Format(e) => Self::Format(format!("{}", e)),
storage::Error::Io(e) => Self::Io(e),
}
}
}
impl From<serializer::Error> for Error {
fn from(error: serializer::Error) -> Self {
match error {
serializer::Error::Format(e) => Self::Format(e),
serializer::Error::Io(e) => Self::Io(e),
}
}
}
pub type Result<T> = result::Result<T, Error>;