context_weaver/core/nodes/
variable.rs

1use crate::WorldInfoNode;
2
3#[derive(Debug, Clone)]
4pub struct VariableNode {
5    value: serde_json::Value
6}
7
8impl VariableNode {
9    pub fn new(value: serde_json::Value) -> Self {
10        Self { value }
11    }
12}
13
14impl WorldInfoNode for VariableNode {
15    fn content(&self) -> Result<String, crate::WorldInfoError> {
16        match &self.value {
17            serde_json::Value::Null => Ok("".to_string()),
18            serde_json::Value::String(s) => Ok(s.replace("\"", "").to_string()),
19            _ => Ok(self.value.to_string())
20        }
21    }
22
23    fn name(&self) -> String {
24        "variable".to_string()
25    }
26
27    fn cloned(&self) -> Box<dyn WorldInfoNode + '_> {
28        Box::new(self.to_owned())
29    }
30}