html_helpers/
error.rs

1use derive_more::{Display, From};
2
3pub type Result<T> = core::result::Result<T, Error>;
4
5#[derive(Debug, Display, From)]
6pub enum Error {
7	#[display("{_0}")]
8	#[from(String, &String, &str)]
9	Custom(String),
10
11	#[display("Selector '{selector}' is invalid.\nCause: {cause}")]
12	SelectorParse { selector: String, cause: String },
13}
14
15// region:    --- Custom
16
17impl Error {
18	/// Creates a custom error from any type that implements `std::error::Error`.
19	pub fn custom_from_err(err: impl std::error::Error) -> Self {
20		Self::Custom(err.to_string())
21	}
22
23	/// Creates a custom error from any type that can be converted into a String.
24	pub fn custom(val: impl Into<String>) -> Self {
25		Self::Custom(val.into())
26	}
27}
28
29// endregion: --- Custom
30
31// region:    --- Error Boilerplate
32
33impl std::error::Error for Error {}
34
35// endregion: --- Error Boilerplate