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)]
6#[display("{self:?}")]
7pub enum Error {
8 #[from(String, &String, &str)]
9 Custom(String),
10
11 // -- Externals
12 #[from]
13 Io(std::io::Error), // as example
14 // Note: Consider adding specific errors for HTML parsing/serialization if needed
15 // #[from]
16 // HtmlParseError(html5ever::driver::ParseError), // Example, if you need to expose it
17}
18
19// region: --- Custom
20
21impl Error {
22 /// Creates a custom error from any type that implements `std::error::Error`.
23 pub fn custom_from_err(err: impl std::error::Error) -> Self {
24 Self::Custom(err.to_string())
25 }
26
27 /// Creates a custom error from any type that can be converted into a String.
28 pub fn custom(val: impl Into<String>) -> Self {
29 Self::Custom(val.into())
30 }
31}
32
33// endregion: --- Custom
34
35// region: --- Error Boilerplate
36
37impl std::error::Error for Error {}
38
39// endregion: --- Error Boilerplate