1use std::{fmt, io};
4
5pub type Result<T> = core::result::Result<T, Error>;
7
8#[derive(Debug)]
10#[non_exhaustive]
11pub enum Error {
12 Io(io::ErrorKind),
14
15 Parse(String),
17
18 Version(semver::Error),
20
21 Resolution(String),
23}
24
25impl fmt::Display for Error {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 Error::Io(kind) => write!(f, "I/O operation failed: {kind}"),
29 Error::Parse(s) => write!(f, "parse error: {s}"),
30 Error::Version(err) => write!(f, "version error: {err}"),
31 Error::Resolution(err) => write!(f, "resolution error: {err}"),
32 }
33 }
34}
35
36impl From<io::Error> for Error {
37 fn from(err: io::Error) -> Self {
38 Error::Io(err.kind())
39 }
40}
41
42impl From<semver::Error> for Error {
43 fn from(err: semver::Error) -> Self {
44 Error::Version(err)
45 }
46}
47
48impl From<std::num::ParseIntError> for Error {
49 fn from(err: std::num::ParseIntError) -> Self {
50 Error::Parse(err.to_string())
51 }
52}
53
54impl std::error::Error for Error {}