Last active
June 4, 2021 05:33
-
-
Save rogeruiz/200437c7a6b35afcb8000794e0d3f0f4 to your computer and use it in GitHub Desktop.
Testing config-rs and shellexpand to read from a YAML file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "test-config-with-shellexpand" | |
version = "0.1.0" | |
edition = "2018" | |
[dependencies] | |
config = "0.11.0" | |
shellexpand = "2.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
value1: test value for config-rs yaml | |
value2: another test value yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate shellexpand; | |
use config::*; | |
fn main() { | |
let config_path = shellexpand::tilde("~/.config/example/e.yaml").to_string(); | |
let mut settings = Config::default(); | |
settings.merge(File::with_name(&config_path)).unwrap(); | |
let value1 = settings.get_string("value1").unwrap(); | |
println!("\n{:?} \n\n-----------", | |
value1); | |
let value2 = settings.get_string("value2").unwrap(); | |
println!("\n{:?} \n\n-----------", | |
value2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment