xshell_venv/
error.rs

1use std::{fmt, io};
2
3/// `Result` from std, with the error type defaulting to xshell_venv's [`Error`].
4pub type Result<T, E = Error> = std::result::Result<T, E>;
5
6/// An error returned by an `xshell` operation.
7pub enum Error {
8    PythonNotDetected(&'static str),
9    Xshell(xshell::Error),
10    Io(io::Error),
11}
12
13impl fmt::Display for Error {
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        match self {
16            Error::PythonNotDetected(s) => write!(f, "{}", s),
17            Error::Xshell(e) => write!(f, "{}", e),
18            Error::Io(e) => write!(f, "{}", e),
19        }
20    }
21}
22
23impl From<xshell::Error> for Error {
24    fn from(error: xshell::Error) -> Error {
25        Error::Xshell(error)
26    }
27}
28
29impl From<&'static str> for Error {
30    fn from(msg: &'static str) -> Error {
31        Error::PythonNotDetected(msg)
32    }
33}
34
35impl From<io::Error> for Error {
36    fn from(value: io::Error) -> Self {
37        Error::Io(value)
38    }
39}
40
41impl fmt::Debug for Error {
42    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43        fmt::Display::fmt(self, f)
44    }
45}
46impl std::error::Error for Error {}