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
use thiserror::Error;
#[derive(Debug, Error, PartialEq)]
pub enum Error {
#[cfg_attr(documenting, doc(cfg(feature = "parser")))]
#[cfg(feature = "parser")]
#[error("Failed to Parse CSS, due to:\n{}", .reason)]
Parse {
reason: String,
#[source]
source: Option<nom::error::VerboseError<String>>,
},
#[error("Failed to Interact with Web API. Are you running in Browser?")]
Web(Option<wasm_bindgen::JsValue>),
}
pub type Result<T> = std::result::Result<T, Error>;
pub trait ResultDisplay<T> {
fn unwrap_display(self) -> T;
fn expect_display(self, msg: &str) -> T;
}
impl<T> ResultDisplay<T> for Result<T> {
fn unwrap_display(self) -> T {
match self {
Ok(m) => m,
Err(e) => panic!("{}", e),
}
}
fn expect_display(self, msg: &str) -> T {
match self {
Ok(m) => m,
Err(e) => panic!("{}: {}", msg, e),
}
}
}