Implement Error for ReadError
This commit is contained in:
parent
8387c8024e
commit
9755eb24b7
1 changed files with 14 additions and 0 deletions
|
@ -13,6 +13,7 @@ pub fn write_single<P: AsRef<Path>, D: Display>(path: P, display: D) -> Result<(
|
|||
}
|
||||
|
||||
/// read_single error
|
||||
#[derive(Debug)]
|
||||
pub enum ReadError<E> {
|
||||
/// IO Error
|
||||
Io(io::Error),
|
||||
|
@ -20,6 +21,19 @@ pub enum ReadError<E> {
|
|||
Parse(E),
|
||||
}
|
||||
|
||||
impl<E: std::error::Error> std::fmt::Display for ReadError<E> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Io(io) => write!(f, "io: {}", io),
|
||||
Self::Parse(e) => write!(f, "parse: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: std::error::Error> std::error::Error for ReadError<E> {
|
||||
|
||||
}
|
||||
|
||||
/// Read something from a file.
|
||||
/// Useful for kernel configuration files.
|
||||
pub fn read_single<P: AsRef<Path>, D: FromStr<Err=E>, E>(path: P) -> Result<D, ReadError<E>> {
|
||||
|
|
Loading…
Reference in a new issue