1use estring::{EString, Pair, SepVec, Trim};
2
3const DOTENV_CONTENT: &str = "
4DATABASE_URL=postgres://user:password@localhost:5432/recipes
5APP_HOST=http://localhost:3000
6";
7
8fn main() -> estring::Result<()> {
9 EString::from(DOTENV_CONTENT)
10 .parse::<Trim<SepVec<Pair<&str, '=', &str>, '\n'>>>()?
11 .iter()
12 .for_each(|p @ Pair(key, value)| {
13 println!("pair: {}", p);
14
15 std::env::set_var(key, value);
16 });
17
18 println!(
19 "envs: {:#?}",
20 std::env::vars()
21 .filter(|(k, ..)| ["DATABASE_URL", "APP_HOST"].contains(&k.as_str()))
22 .collect::<Vec<_>>()
23 );
24
25 Ok(())
26}