Skip to main content

dotenv_typed/error/
impl.rs

1use super::*;
2
3/// Formats [`EnvError`] into a human-readable diagnostic message.
4impl fmt::Display for EnvError {
5    /// Writes the diagnostic text to `f`.
6    ///
7    /// # Arguments
8    ///
9    /// - `&mut fmt::Formatter<'_>` - Destination formatter.
10    ///
11    /// # Returns
12    ///
13    /// - `fmt::Result` - Formatting outcome.
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        match self {
16            Self::MissingKey(key) => write!(f, "{ERR_MISSING_PREFIX}{key}"),
17            Self::ParseError { key, detail } => write!(f, "{ERR_PARSE_PREFIX}{key}: {detail}"),
18            Self::InvalidSyntax { line, detail } => {
19                write!(f, "{ERR_SYNTAX_PREFIX}{line}: {detail}")
20            }
21            Self::Io(msg) => write!(f, "{ERR_IO_PREFIX}{msg}"),
22        }
23    }
24}
25
26/// Marks [`EnvError`] as a standard error.
27impl Error for EnvError {}