Skip to main content

ergo_runtime/source/implementations/string/
impl.rs

1use std::collections::HashMap;
2
3use crate::common::Value;
4use crate::runtime::ExecutionContext;
5use crate::source::{ParameterValue, SourcePrimitive, SourcePrimitiveManifest};
6
7use super::manifest::string_source_manifest;
8
9pub struct StringSource {
10    manifest: SourcePrimitiveManifest,
11}
12
13impl StringSource {
14    pub fn new() -> Self {
15        Self {
16            manifest: string_source_manifest(),
17        }
18    }
19}
20
21impl Default for StringSource {
22    fn default() -> Self {
23        Self::new()
24    }
25}
26
27impl SourcePrimitive for StringSource {
28    fn manifest(&self) -> &SourcePrimitiveManifest {
29        &self.manifest
30    }
31
32    fn produce(
33        &self,
34        parameters: &HashMap<String, ParameterValue>,
35        _ctx: &ExecutionContext,
36    ) -> HashMap<String, Value> {
37        let value = parameters
38            .get("value")
39            .and_then(|v| match v {
40                ParameterValue::String(s) => Some(s.clone()),
41                _ => None,
42            })
43            .unwrap_or_default();
44
45        HashMap::from([("value".to_string(), Value::String(value))])
46    }
47}