axconfig_gen/
lib.rs

1#![doc = include_str!("../README.md")]
2
3mod config;
4mod output;
5mod ty;
6mod value;
7
8#[cfg(test)]
9mod tests;
10
11use toml_edit::TomlError;
12
13pub use self::config::{Config, ConfigItem};
14pub use self::output::OutputFormat;
15pub use self::ty::ConfigType;
16pub use self::value::ConfigValue;
17
18/// The error type on config parsing.
19pub enum ConfigErr {
20    /// TOML parsing error.
21    Parse(TomlError),
22    /// Invalid config value.
23    InvalidValue,
24    /// Invalid config type.
25    InvalidType,
26    /// Config value and type mismatch.
27    ValueTypeMismatch,
28    /// Other error.
29    Other(String),
30}
31
32impl From<TomlError> for ConfigErr {
33    fn from(e: TomlError) -> Self {
34        Self::Parse(e)
35    }
36}
37
38impl core::fmt::Display for ConfigErr {
39    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
40        match self {
41            Self::Parse(e) => write!(f, "{}", e),
42            Self::InvalidValue => write!(f, "Invalid config value"),
43            Self::InvalidType => write!(f, "Invalid config type"),
44            Self::ValueTypeMismatch => write!(f, "Config value and type mismatch"),
45            Self::Other(s) => write!(f, "{}", s),
46        }
47    }
48}
49
50impl core::fmt::Debug for ConfigErr {
51    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
52        write!(f, "{}", self)
53    }
54}
55
56/// A specialized [`Result`] type with [`ConfigErr`] as the error type.
57pub type ConfigResult<T> = Result<T, ConfigErr>;