-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
Error
type to works with errors
- Loading branch information
Showing
2 changed files
with
40 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::fmt; | ||
|
||
/// Result type for the library | ||
pub type Result<T> = std::result::Result<T, Error>; | ||
|
||
/// Error enum, used to return errors from the library. | ||
#[derive(Debug)] | ||
pub enum Error { | ||
/// Error from the hound crate | ||
Hound(hound::Error), | ||
/// IO error, such as file not found | ||
Io(std::io::Error), | ||
/// Larg file size error (maxnimum file size is 4 GB) | ||
LargeFileSize, | ||
} | ||
|
||
impl From<hound::Error> for Error { | ||
fn from(err: hound::Error) -> Self { | ||
Error::Hound(err) | ||
} | ||
} | ||
|
||
impl From<std::io::Error> for Error { | ||
fn from(err: std::io::Error) -> Self { | ||
Error::Io(err) | ||
} | ||
} | ||
|
||
impl fmt::Display for Error { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Error::Hound(err) => write!(f, "Hound error: {}", err), | ||
Error::Io(err) => write!(f, "IO error: {}", err), | ||
Error::LargeFileSize => write!(f, "File size is too large, maximum file size is 4 GB"), | ||
} | ||
} | ||
} |
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