Add Source trait and implement it for files (TOML and YAML for now)

This commit is contained in:
Lukas Kalbertodt
2021-05-16 15:27:47 +02:00
parent 6d1e9e99c6
commit 32fbfd3a5a
8 changed files with 268 additions and 25 deletions

View File

@@ -0,0 +1,2 @@
http:
port: 4321

View File

@@ -0,0 +1,2 @@
[cat]
foo = "yes"

View File

@@ -1,5 +1,5 @@
use std::net::IpAddr;
use confique::{Config, Partial};
use std::{net::IpAddr, path::Path};
use confique::Config;
#[derive(Debug, Config)]
struct Conf {
@@ -26,6 +26,13 @@ struct Cat {
}
fn main() {
println!("{:#?}", Conf::from_partial(<Conf as Config>::Partial::default_values()));
fn main() -> Result<(), anyhow::Error> {
let r = Conf::from_sources(&[
&Path::new("examples/files/simple.toml"),
&Path::new("examples/files/etc/simple.yaml"),
])?;
println!("{:#?}", r);
Ok(())
}