1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use std::{
error::Error,
fmt,
io,
};
#[derive(Debug)]
#[non_exhaustive]
pub enum AssetError {
IoError(io::Error),
LoadError(Box<dyn Error + Send + Sync>),
#[deprecated = "This error kind is not emitted by assets_manager and will be removed in a future release"]
InvalidType,
}
impl From<io::Error> for AssetError {
fn from(err: io::Error) -> Self {
Self::IoError(err)
}
}
#[allow(deprecated)]
impl fmt::Display for AssetError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AssetError::IoError(err) => write!(f, "An I/O error occurred while trying to load an asset : {}", err),
AssetError::LoadError(err) => write!(f, "An conversion error occurred while trying to load an asset : {}", err),
AssetError::InvalidType => write!(f, "An asset was loaded with a wrong type"),
}
}
}
impl Error for AssetError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
AssetError::IoError(err) => Some(err),
AssetError::LoadError(err) => Some(err.as_ref()),
_ => None,
}
}
}