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
63
toml-config/src/config/spanned.rs
Normal file
63
toml-config/src/config/spanned.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
use crate::{
|
||||
config::parser::{ParseResult, Parser},
|
||||
toml::{toml_span::Spanned, toml_value::Value},
|
||||
};
|
||||
|
||||
impl Spanned<&Value> {
|
||||
pub fn parse<P: Parser>(&self, parser: &mut P) -> ParseResult<P> {
|
||||
self.value.parse(self.span, parser)
|
||||
}
|
||||
|
||||
pub fn parse_map<P: Parser, E>(
|
||||
&self,
|
||||
parser: &mut P,
|
||||
) -> Result<<P as Parser>::Value, Spanned<E>>
|
||||
where
|
||||
<P as Parser>::Error: Into<E>,
|
||||
{
|
||||
self.parse(parser).map_spanned_err(|e| e.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Spanned<Value> {
|
||||
pub fn parse<P: Parser>(&self, parser: &mut P) -> ParseResult<P> {
|
||||
self.as_ref().parse(parser)
|
||||
}
|
||||
|
||||
pub fn parse_map<P: Parser, E>(
|
||||
&self,
|
||||
parser: &mut P,
|
||||
) -> Result<<P as Parser>::Value, Spanned<E>>
|
||||
where
|
||||
<P as Parser>::Error: Into<E>,
|
||||
{
|
||||
self.as_ref().parse_map(parser)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SpannedErrorExt {
|
||||
type T;
|
||||
type E;
|
||||
|
||||
fn map_spanned_err<U, F>(self, f: F) -> Result<Self::T, Spanned<U>>
|
||||
where
|
||||
F: FnOnce(Self::E) -> U;
|
||||
}
|
||||
|
||||
impl<T, E> SpannedErrorExt for Result<T, Spanned<E>> {
|
||||
type T = T;
|
||||
type E = E;
|
||||
|
||||
fn map_spanned_err<U, F>(self, f: F) -> Result<Self::T, Spanned<U>>
|
||||
where
|
||||
F: FnOnce(Self::E) -> U,
|
||||
{
|
||||
match self {
|
||||
Ok(v) => Ok(v),
|
||||
Err(e) => Err(Spanned {
|
||||
span: e.span,
|
||||
value: f(e.value),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue