vc-runtime 0.1.0

Runtime backend for Visual Compiler
Documentation
//! Runtime bindings for workflow injection.

use super::binding::BindingKey;
use super::error::WorkflowError;
use serde_json::Value;
use std::collections::HashMap;

#[derive(Debug, Clone, Default)]
pub struct RuntimeBindings {
    bindings: HashMap<BindingKey, Value>,
}

impl RuntimeBindings {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn insert(&mut self, key: BindingKey, value: Value) {
        self.bindings.insert(key, value);
    }

    pub fn lookup(&self, key: &BindingKey) -> Result<Value, WorkflowError> {
        self.bindings
            .get(key)
            .cloned()
            .ok_or_else(|| WorkflowError::MissingBinding { key: key.as_str().to_string() })
    }
}