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
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn clones_share_an_immutable_snapshot() {
31 let env = InvocationEnv::single("effort", Value::Str("high".into()));
32 let cloned = env.clone();
33
34 assert!(matches!(
35 cloned.get("effort"),
36 Some(Value::Str(value)) if value == "high"
37 ));
38 assert!(cloned.get("missing").is_none());
39 }
40}