-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crossterm::ErrorKind to io::Error (#553)
- Loading branch information
Showing
11 changed files
with
58 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,8 @@ | ||
//! Module containing error handling logic. | ||
|
||
use std::{ | ||
fmt::{self, Display, Formatter}, | ||
io, | ||
}; | ||
|
||
use crate::impl_from; | ||
use std::io; | ||
|
||
/// The `crossterm` result type. | ||
pub type Result<T> = std::result::Result<T, ErrorKind>; | ||
|
||
/// Wrapper for all errors that can occur in `crossterm`. | ||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub enum ErrorKind { | ||
IoError(io::Error), | ||
FmtError(fmt::Error), | ||
Utf8Error(std::string::FromUtf8Error), | ||
ParseIntError(std::num::ParseIntError), | ||
ResizingTerminalFailure(String), | ||
SettingTerminalTitleFailure, | ||
} | ||
|
||
impl std::error::Error for ErrorKind { | ||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
match self { | ||
ErrorKind::IoError(e) => Some(e), | ||
ErrorKind::FmtError(e) => Some(e), | ||
ErrorKind::Utf8Error(e) => Some(e), | ||
ErrorKind::ParseIntError(e) => Some(e), | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
impl Display for ErrorKind { | ||
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { | ||
match *self { | ||
ErrorKind::IoError(_) => write!(fmt, "IO-error occurred"), | ||
ErrorKind::ResizingTerminalFailure(_) => write!(fmt, "Cannot resize the terminal"), | ||
_ => write!(fmt, "Some error has occurred"), | ||
} | ||
} | ||
} | ||
|
||
impl_from!(io::Error, ErrorKind::IoError); | ||
impl_from!(fmt::Error, ErrorKind::FmtError); | ||
impl_from!(std::string::FromUtf8Error, ErrorKind::Utf8Error); | ||
impl_from!(std::num::ParseIntError, ErrorKind::ParseIntError); | ||
pub type ErrorKind = io::Error; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.