Skip to main content

ergo_runtime/compute/implementations/append/
impl.rs

1use std::collections::HashMap;
2
3use crate::common::Value;
4use crate::compute::{ComputeError, ComputePrimitive, ComputePrimitiveManifest, PrimitiveState};
5
6use super::manifest::append_manifest;
7
8pub struct Append {
9    manifest: ComputePrimitiveManifest,
10}
11
12impl Append {
13    pub fn new() -> Self {
14        Self {
15            manifest: append_manifest(),
16        }
17    }
18}
19
20impl Default for Append {
21    fn default() -> Self {
22        Self::new()
23    }
24}
25
26impl ComputePrimitive for Append {
27    fn manifest(&self) -> &ComputePrimitiveManifest {
28        &self.manifest
29    }
30
31    fn compute(
32        &self,
33        inputs: &HashMap<String, Value>,
34        _parameters: &HashMap<String, Value>,
35        _state: Option<&mut PrimitiveState>,
36    ) -> Result<HashMap<String, Value>, ComputeError> {
37        let mut series = inputs
38            .get("series")
39            .and_then(|v| v.as_series())
40            .cloned()
41            .expect("missing required series input 'series'");
42        let value = inputs
43            .get("value")
44            .and_then(|v| v.as_number())
45            .expect("missing required numeric input 'value'");
46
47        series.push(value);
48
49        Ok(HashMap::from([(
50            "result".to_string(),
51            Value::Series(series),
52        )]))
53    }
54}