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>),
#[error("Failed to read from manager. Did the renderer panic?")]
ReadFailed,
}
impl From<std::convert::Infallible> for Error {
fn from(infallible: std::convert::Infallible) -> Self {
match infallible {}
}
}
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}"),
}
}
}