Commit 364209299d

364209299d5bcf2569b06b2ca0add56e98f012c3

parent: e7f2bba5c2

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2023-01-05 21:59 UTC

0.6.1

Layout: unified · split

src/global/functions/envs.rs added +27
@@ -0,0 +1,27 @@
1use std::env;
2
3/// removes all environment variables in a vector
4pub fn clear_envs(modified: &mut Vec<(String, String)>) {
5 modified.iter().for_each(|(key, _)| env::remove_var(key));
6 modified.clear();
7}
8
9/// set all environment variables in an interator, while pushing changes into the modified vector
10/// to keep track of changes
11pub fn set_envs<T: Iterator<Item = (String, String)>>(
12 envs: T,
13 modified: &mut Vec<(String, String)>,
14) {
15 envs.for_each(|(key, value)| {
16 if !modified.iter().any(|(k, _)| k == &key) {
17 modified.push((key.clone(), value.clone()));
18 }
19 env::set_var(key, value);
20 });
21}
22
23/// replace env placeholder in a string with the value of the env
24pub fn apply_envs(mut s: String) -> String {
25 env::vars().for_each(|(key, value)| s = s.replace(&format!("${{{key}}}"), &value));
26 s
27}
src/global/structs/state_env.rs added +10
@@ -0,0 +1,10 @@
1use typemap::Key;
2
3/// holds all modified envs that belongs to the page
4/// stores (key, value) pairs
5#[derive(Default, Clone)]
6pub struct StateEnvs(pub Vec<(String, String)>);
7
8impl Key for StateEnvs {
9 type Value = Self;
10}