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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use crate::prelude::*;
use alloc::format;
use alloc::string::String;
use core::any::TypeId;
use displaydoc::Display;
#[non_exhaustive]
#[derive(Display, Debug)]
pub enum Error {
#[displaydoc("Missing resource for key: {0}")]
MissingResourceKey(ResourceKey),
#[displaydoc("Missing resource for request: {0}")]
MissingResourceOptions(DataRequest),
#[displaydoc("Resource was filtered: {1}: {0}")]
FilteredResource(DataRequest, String),
#[displaydoc("Requested key needs language identifier in request: {0}")]
NeedsLanguageIdentifier(DataRequest),
#[displaydoc("Complete type information is required")]
NeedsTypeInfo,
#[displaydoc("Payload is missing")]
MissingPayload,
#[displaydoc("Mismatched type: payload is {actual:?} (expected from generic type paramenter: {generic:?})")]
MismatchedType {
actual: Option<TypeId>,
generic: Option<TypeId>,
},
#[displaydoc("Could not unwrap Rc due to multiple references")]
MultipleReferences,
#[cfg(feature = "erased-serde")]
#[displaydoc("Serde error: {0}")]
Serde(erased_serde::Error),
#[displaydoc("Failed to load resource: {0}")]
Resource(String),
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}
#[cfg(feature = "erased-serde")]
impl From<erased_serde::Error> for Error {
fn from(e: erased_serde::Error) -> Self {
Error::Serde(e)
}
}
impl From<String> for Error {
fn from(e: String) -> Self {
Error::Resource(e)
}
}
impl Error {
pub fn new_resc_error<T>(err: T) -> Self
where
T: core::fmt::Display,
{
Self::Resource(format!("{}", err))
}
}
impl From<&ResourceKey> for Error {
fn from(resc_key: &ResourceKey) -> Self {
Self::MissingResourceKey(*resc_key)
}
}
impl From<DataRequest> for Error {
fn from(req: DataRequest) -> Self {
Self::MissingResourceOptions(req)
}
}