mirror of
https://github.com/OMGeeky/confique.git
synced 2026-01-07 04:01:26 +01:00
Add support for array default values
This commit is contained in:
@@ -62,3 +62,19 @@ pub fn from_env_with<T>(
|
||||
}.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// `serde` does not implement `IntoDeserializer` for fixed size arrays. This
|
||||
/// helper type is just used for this purpose.
|
||||
pub struct ArrayIntoDeserializer<T, const N: usize>(pub [T; N]);
|
||||
|
||||
impl<'de, T, E, const N: usize> serde::de::IntoDeserializer<'de, E> for ArrayIntoDeserializer<T, N>
|
||||
where
|
||||
T: serde::de::IntoDeserializer<'de, E>,
|
||||
E: serde::de::Error,
|
||||
{
|
||||
type Deserializer = serde::de::value::SeqDeserializer<std::array::IntoIter<T, N>, E>;
|
||||
|
||||
fn into_deserializer(self) -> Self::Deserializer {
|
||||
serde::de::value::SeqDeserializer::new(self.0.into_iter())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ pub enum Expr {
|
||||
Float(Float),
|
||||
Integer(Integer),
|
||||
Bool(bool),
|
||||
Array(&'static [Expr]),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
|
||||
12
src/toml.rs
12
src/toml.rs
@@ -193,6 +193,18 @@ impl fmt::Display for PrintExpr {
|
||||
Expr::Float(v) => v.fmt(f),
|
||||
Expr::Integer(v) => v.fmt(f),
|
||||
Expr::Bool(v) => v.fmt(f),
|
||||
Expr::Array(items) => {
|
||||
// TODO: pretty printing of long arrays onto multiple lines?
|
||||
f.write_char('[')?;
|
||||
for (i, item) in items.iter().enumerate() {
|
||||
if i != 0 {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
PrintExpr(item).fmt(f)?;
|
||||
}
|
||||
f.write_char(']')?;
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
src/yaml.rs
12
src/yaml.rs
@@ -184,6 +184,18 @@ impl fmt::Display for PrintExpr {
|
||||
Expr::Float(v) => v.fmt(f),
|
||||
Expr::Integer(v) => v.fmt(f),
|
||||
Expr::Bool(v) => v.fmt(f),
|
||||
Expr::Array(items) => {
|
||||
// TODO: pretty printing of long arrays onto multiple lines?
|
||||
f.write_char('[')?;
|
||||
for (i, item) in items.iter().enumerate() {
|
||||
if i != 0 {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
PrintExpr(item).fmt(f)?;
|
||||
}
|
||||
f.write_char(']')?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user