-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy patherror.rs
More file actions
58 lines (50 loc) · 1.63 KB
/
error.rs
File metadata and controls
58 lines (50 loc) · 1.63 KB
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
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum UnrecognizedValue {
UnknownResolver(String),
UnknownEdition(String),
}
impl std::fmt::Display for UnrecognizedValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
UnrecognizedValue::UnknownResolver(resolver) => {
write!(f, "Unrecognized resolver version: {resolver}")
}
UnrecognizedValue::UnknownEdition(edition) => {
write!(f, "Unrecognized Rust edition: {edition}")
}
}
}
}
impl std::error::Error for UnrecognizedValue {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
UnrecognizedValue(UnrecognizedValue),
TomlParseError(toml::de::Error), // Adjust for the specific Serde library in use (e.g., `serde_json` or `serde_yaml`)
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::UnrecognizedValue(msg) => write!(f, "{msg}"),
Error::TomlParseError(err) => write!(f, "Failed to parse Cargo.toml: {err}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::UnrecognizedValue(err) => Some(err),
Error::TomlParseError(err) => Some(err),
}
}
}
impl From<UnrecognizedValue> for Error {
fn from(value: UnrecognizedValue) -> Self {
Error::UnrecognizedValue(value)
}
}
impl From<toml::de::Error> for Error {
fn from(err: toml::de::Error) -> Self {
Error::TomlParseError(err)
}
}