dialoguer/
error.rs

1use std::{fmt, io::Error as IoError, result::Result as StdResult};
2
3/// Possible errors returned by prompts.
4#[derive(Debug)]
5pub enum Error {
6    /// Error while executing IO operations.
7    IO(IoError),
8}
9
10impl fmt::Display for Error {
11    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12        match self {
13            Self::IO(io) => write!(f, "IO error: {}", io),
14        }
15    }
16}
17
18impl std::error::Error for Error {}
19
20impl From<IoError> for Error {
21    fn from(err: IoError) -> Self {
22        Self::IO(err)
23    }
24}
25
26/// Result type where errors are of type [Error](enum@Error).
27pub type Result<T = ()> = StdResult<T, Error>;
28
29impl From<Error> for IoError {
30    fn from(value: Error) -> Self {
31        match value {
32            Error::IO(err) => err,
33            // If other error types are added in the future:
34            // err => IoError::new(std::io::ErrorKind::Other, err),
35        }
36    }
37}