config: change default config to use toml-based configuration
This commit is contained in:
parent
e24a61bc62
commit
3cebf651c5
58 changed files with 14093 additions and 145 deletions
42
toml-config/src/config/parsers/env.rs
Normal file
42
toml-config/src/config/parsers/env.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
use {
|
||||
crate::{
|
||||
config::{
|
||||
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
parsers::{StringParser, StringParserError},
|
||||
},
|
||||
toml::{
|
||||
toml_span::{Span, Spanned},
|
||||
toml_value::Value,
|
||||
},
|
||||
},
|
||||
indexmap::IndexMap,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum EnvParserError {
|
||||
#[error(transparent)]
|
||||
Expected(#[from] UnexpectedDataType),
|
||||
#[error(transparent)]
|
||||
String(#[from] StringParserError),
|
||||
}
|
||||
|
||||
pub struct EnvParser;
|
||||
|
||||
impl Parser for EnvParser {
|
||||
type Value = Vec<(String, String)>;
|
||||
type Error = EnvParserError;
|
||||
const EXPECTED: &'static [DataType] = &[DataType::Table];
|
||||
|
||||
fn parse_table(
|
||||
&mut self,
|
||||
_span: Span,
|
||||
table: &IndexMap<Spanned<String>, Spanned<Value>>,
|
||||
) -> ParseResult<Self> {
|
||||
let mut envs = vec![];
|
||||
for (k, v) in table {
|
||||
envs.push((k.value.to_string(), v.parse_map(&mut StringParser)?));
|
||||
}
|
||||
Ok(envs)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue