Skip to main content

ergo_runtime/action/implementations/context_set_bool/
impl.rs

1use std::collections::HashMap;
2
3use crate::action::{
4    ActionOutcome, ActionPrimitive, ActionPrimitiveManifest, ActionValue, ParameterValue,
5};
6
7use super::manifest::context_set_bool_manifest;
8
9pub struct ContextSetBoolAction {
10    manifest: ActionPrimitiveManifest,
11}
12
13impl ContextSetBoolAction {
14    pub fn new() -> Self {
15        Self {
16            manifest: context_set_bool_manifest(),
17        }
18    }
19}
20
21impl Default for ContextSetBoolAction {
22    fn default() -> Self {
23        Self::new()
24    }
25}
26
27impl ActionPrimitive for ContextSetBoolAction {
28    fn manifest(&self) -> &ActionPrimitiveManifest {
29        &self.manifest
30    }
31
32    fn execute(
33        &self,
34        inputs: &HashMap<String, ActionValue>,
35        _parameters: &HashMap<String, ParameterValue>,
36    ) -> HashMap<String, ActionValue> {
37        let _event = inputs
38            .get("event")
39            .and_then(|v| v.as_event())
40            .expect("missing required event input 'event'");
41
42        let _value = inputs
43            .get("value")
44            .and_then(|v| match v {
45                ActionValue::Bool(b) => Some(*b),
46                _ => None,
47            })
48            .expect("missing required bool input 'value'");
49
50        HashMap::from([(
51            "outcome".to_string(),
52            ActionValue::Event(ActionOutcome::Attempted),
53        )])
54    }
55}