atman_runtime/
invocation_env.rs1use std::collections::BTreeMap;
2use std::sync::Arc;
3
4use crate::value::Value;
5
6#[derive(Clone, Debug, Default)]
9pub struct InvocationEnv(Arc<BTreeMap<String, Value>>);
10
11impl InvocationEnv {
12 pub fn from_values(values: impl IntoIterator<Item = (String, Value)>) -> Self {
13 Self(Arc::new(values.into_iter().collect()))
14 }
15
16 pub fn single(key: impl Into<String>, value: Value) -> Self {
17 Self::from_values([(key.into(), value)])
18 }
19
20 pub fn get(&self, key: &str) -> Option<&Value> {
21 self.0.get(key)
22 }
23
24 pub fn is_empty(&self) -> bool {
25 self.0.is_empty()
26 }
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 #[test]
34 fn clones_share_an_immutable_snapshot() {
35 let env = InvocationEnv::single("effort", Value::Str("high".into()));
36 let cloned = env.clone();
37
38 assert!(matches!(
39 cloned.get("effort"),
40 Some(Value::Str(value)) if value == "high"
41 ));
42 assert!(cloned.get("missing").is_none());
43 }
44}