data2sound/
errors.rs

1use std::fmt;
2
3/// Result type for the library
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// Error enum, used to return errors from the library.
7#[derive(Debug)]
8pub enum Error {
9    /// IO error, such as file not found
10    Io(std::io::Error),
11    /// Larg file size error (maxnimum file size is 4 GB)
12    LargeFileSize,
13    /// Invalid wav file error
14    InvalidWavFile(String),
15}
16impl From<std::io::Error> for Error {
17    fn from(err: std::io::Error) -> Self {
18        Error::Io(err)
19    }
20}
21
22impl fmt::Display for Error {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            Error::Io(err) => write!(f, "IO error: {}", err),
26            Error::LargeFileSize => write!(f, "File size is too large, maximum file size is 4 GB"),
27            Error::InvalidWavFile(msg) => write!(f, "Invalid wav file, {}", msg),
28        }
29    }
30}