1use crate::{CargoRustcEnvMap, CargoWarning, VergenKey, constants::VERGEN_IDEMPOTENT_DEFAULT};
2use std::env;
3
4#[cfg_attr(
16 feature = "build",
17 doc = r" add_default_map_entry(false, VergenKey::BuildDate, &mut map, &mut warning);
18assert_eq!(1, map.len());
19assert_eq!(1, warning.len());"
20)]
21pub fn add_default_map_entry(
25 idempotent: bool,
26 key: VergenKey,
27 map: &mut CargoRustcEnvMap,
28 warnings: &mut CargoWarning,
29) {
30 if let Ok(value) = env::var(key.name()) {
31 add_map_entry(key, value, map);
32 warnings.push(format!("{} overidden", key.name()));
33 } else if idempotent {
34 add_map_entry(key, VERGEN_IDEMPOTENT_DEFAULT, map);
35 warnings.push(format!("{} set to default", key.name()));
36 } else {
37 warnings.push(format!("Unable to set {}", key.name()));
38 }
39}
40
41#[cfg_attr(
49 feature = "build",
50 doc = r#"add_map_entry(VergenKey::BuildDate, "test", &mut map);
51assert_eq!(1, map.len());"#
52)]
53pub fn add_map_entry<T>(key: VergenKey, value: T, map: &mut CargoRustcEnvMap)
56where
57 T: Into<String>,
58{
59 let _old = map.insert(key, value.into());
60}
61
62#[cfg_attr(
75 feature = "build",
76 doc = r"_ = map.insert(VergenKey::BuildDate, VERGEN_IDEMPOTENT_DEFAULT.to_string());"
77)]
78#[cfg_attr(feature = "build", doc = r"assert_eq!(1, count_idempotent(&map));")]
79#[must_use]
82pub fn count_idempotent(map: &CargoRustcEnvMap) -> usize {
83 map.values()
84 .filter(|x| *x == VERGEN_IDEMPOTENT_DEFAULT)
85 .count()
86}