config_tools/
outcome.rs

1use crate::Config;
2
3/// The result of loading a configuration, indicating whether the config was
4/// loaded from a file or constructed from a default fallback.
5///
6/// Use [`LoadOutcome::used_default`] to determine which case occurred,
7/// or extract the inner config using [`LoadOutcome::into_inner`].
8#[derive(Clone, Debug, PartialEq)]
9pub enum LoadOutcome {
10    FromDefault(Config),
11    FromFile(Config),
12}
13
14impl LoadOutcome {
15    #[must_use]
16    pub fn into_inner(self) -> Config {
17        match self {
18            LoadOutcome::FromDefault(cfg) | LoadOutcome::FromFile(cfg) => cfg
19        }
20    }
21
22    pub fn as_mut(&mut self) -> &mut Config {
23        match self {
24            LoadOutcome::FromDefault(cfg) | LoadOutcome::FromFile(cfg) => cfg
25        }
26    }
27
28    pub fn as_ref(&self) -> &Config {
29        match self {
30            LoadOutcome::FromDefault(cfg) | LoadOutcome::FromFile(cfg) => cfg
31        }
32    }
33
34    pub fn used_default(&self) -> bool {
35        matches!(self, LoadOutcome::FromDefault(_))
36    }
37}