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
|
use serde::Serialize;
#[derive(thiserror::Error, Debug)]
pub enum SpaceError {
#[error("Space not found")]
SpaceNotFound,
#[error("Path format error: {0}")]
PathFormatError(#[from] just_fmt::fmt_path::PathFormatError),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Other: {0}")]
Other(String),
#[error("Require empty directory")]
RequireEmptyDirectory,
#[error("Config file already exist")]
ConfigFileAlreadyExist,
}
impl Serialize for SpaceError {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&self.to_string())
}
}
impl PartialEq for SpaceError {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Io(_), Self::Io(_)) => true,
_ => core::mem::discriminant(self) == core::mem::discriminant(other),
}
}
}
|