better_config_core/
error.rs

1use std::{error::Error as StdError, fmt};
2
3#[derive(Debug)]
4pub enum Error {
5    LoadFileError {
6        name: String,
7        source: Option<Box<dyn StdError + Send + Sync>>,
8    },
9}
10impl fmt::Display for Error {
11    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12        match self {
13            Error::LoadFileError { name, source } => {
14                write!(f, "Failed to load file {}", name)?;
15                if let Some(source) = source {
16                    write!(f, ": {}", source)?;
17                }
18                Ok(())
19            }
20        }
21    }
22}
23
24impl StdError for Error {
25    fn source(&self) -> Option<&(dyn StdError + 'static)> {
26        match self {
27            Error::LoadFileError { source, .. } => {
28                source.as_deref().map(|e| e as &(dyn StdError + 'static))
29            }
30        }
31    }
32}