1use std::fmt::Display;
2
3pub type InvalidConfigError = Box<dyn Display>;
5
6pub struct FormattedConfigError {
8 func: Box<dyn Fn() -> String>,
9}
10
11impl FormattedConfigError {
12 #[allow(clippy::new_ret_no_self)]
13 pub fn new<F: Fn() -> String + 'static>(func: F) -> Box<dyn Display> {
14 Box::new(Self {
15 func: Box::new(func),
16 })
17 }
18}
19
20impl Display for FormattedConfigError {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 let string = (self.func)();
23 write!(f, "{string}")
24 }
25}