This repository has been archived on 2024-07-25. You can view files and clone it, but cannot push or open issues or pull requests.
estring/examples/dotenv.rs
2022-07-25 19:57:40 +00:00

28 lines
707 B
Rust

use estring::low::Trim;
use estring::structs::{Pair, SepVec};
use estring::EString;
const DOTENV_CONTENT: &str = "
DATABASE_URL=postgres://user:password@localhost:5432/recipes
APP_HOST=http://localhost:3000
";
fn main() -> Result<(), estring::ParseError> {
EString::from(DOTENV_CONTENT)
.parse::<Trim<SepVec<Pair<&str, '=', &str>, '\n'>>>()?
.iter()
.for_each(|p @ Pair(key, value)| {
println!("pair: {}", p);
std::env::set_var(key, value);
});
println!(
"envs: {:#?}",
std::env::vars()
.filter(|(k, ..)| ["DATABASE_URL", "APP_HOST"].contains(&k.as_str()))
.collect::<Vec<_>>()
);
Ok(())
}