@@ -5,6 +5,10 @@ pub type Result<T> = std::result::Result<T, AudioError>;
55
66#[ derive( Debug ) ]
77pub enum AudioError {
8+ // File data related errors
9+ /// Attempting to read/write an abnormally large amount of data
10+ TooMuchData ,
11+
812 /// Errors that arise while decoding text
913 TextDecode ( & ' static str ) ,
1014
@@ -15,6 +19,8 @@ pub enum AudioError {
1519 StringFromUtf8 ( std:: string:: FromUtf8Error ) ,
1620 /// Unable to convert bytes to a str
1721 StrFromUtf8 ( std:: str:: Utf8Error ) ,
22+ /// Failure to allocate enough memory
23+ Alloc ( std:: collections:: TryReserveError ) ,
1824 /// This should **never** be encountered
1925 Infallible ( std:: convert:: Infallible ) ,
2026}
@@ -37,6 +43,12 @@ impl From<std::str::Utf8Error> for AudioError {
3743 }
3844}
3945
46+ impl From < std:: collections:: TryReserveError > for AudioError {
47+ fn from ( input : std:: collections:: TryReserveError ) -> Self {
48+ AudioError :: Alloc ( input)
49+ }
50+ }
51+
4052impl From < std:: convert:: Infallible > for AudioError {
4153 fn from ( input : std:: convert:: Infallible ) -> Self {
4254 AudioError :: Infallible ( input)
@@ -46,12 +58,20 @@ impl From<std::convert::Infallible> for AudioError {
4658impl Display for AudioError {
4759 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
4860 match self {
61+ AudioError :: TextDecode ( message) => write ! ( f, "Text decoding: {message}" ) ,
62+
4963 // Conversions
5064 AudioError :: StringFromUtf8 ( err) => write ! ( f, "{err}" ) ,
5165 AudioError :: StrFromUtf8 ( err) => write ! ( f, "{err}" ) ,
5266 AudioError :: Io ( err) => write ! ( f, "{err}" ) ,
53- AudioError :: TextDecode ( message ) => write ! ( f, "Text decoding: {message }" ) ,
67+ AudioError :: Alloc ( err ) => write ! ( f, "{err }" ) ,
5468 AudioError :: Infallible ( _) => write ! ( f, "An expected condition was not upheld" ) ,
69+
70+ // Files
71+ AudioError :: TooMuchData => write ! (
72+ f,
73+ "Attempted to read/write an abnormally large amount of data"
74+ ) ,
5575 }
5676 }
5777}
0 commit comments