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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::{error, ffi::NulError, fmt};
#[derive(Debug)]
pub enum SpineError {
ParsingFailed { reason: String },
NulError(NulError),
NotFound { what: String, name: String },
FailedToReadFile { file: String },
}
impl SpineError {
pub(crate) fn new_from_spine(reason: &str) -> Self {
Self::ParsingFailed {
reason: reason.to_owned(),
}
}
pub(crate) fn new_not_found(what: &str, name: &str) -> Self {
Self::NotFound {
what: what.to_owned(),
name: name.to_owned(),
}
}
}
impl From<NulError> for SpineError {
fn from(err: NulError) -> Self {
Self::NulError(err)
}
}
impl fmt::Display for SpineError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SpineError::ParsingFailed { reason } => {
write!(f, "Spine parsing failed: {}", reason)?;
Ok(())
}
SpineError::NulError(error) => {
write!(f, "Nul error: {}", error)?;
Ok(())
}
SpineError::NotFound { what, name } => {
write!(f, "{} not found: {}", what, name)?;
Ok(())
}
Self::FailedToReadFile { file } => {
write!(f, "Failed to read file: {}", file)?;
Ok(())
}
}
}
}
impl error::Error for SpineError {}