blueprint_engine_core/value/
io.rs

1use std::collections::HashMap;
2use std::sync::Arc;
3
4use indexmap::IndexMap;
5use tokio::sync::RwLock;
6
7use super::Value;
8
9#[derive(Debug, Clone)]
10pub struct HttpResponse {
11    pub status: i64,
12    pub body: String,
13    pub headers: HashMap<String, String>,
14}
15
16impl HttpResponse {
17    pub fn get_attr(&self, name: &str) -> Option<Value> {
18        match name {
19            "status" => Some(Value::Int(self.status)),
20            "body" => Some(Value::String(Arc::new(self.body.clone()))),
21            "headers" => {
22                let map: IndexMap<String, Value> = self
23                    .headers
24                    .iter()
25                    .map(|(k, v)| (k.clone(), Value::String(Arc::new(v.clone()))))
26                    .collect();
27                Some(Value::Dict(Arc::new(RwLock::new(map))))
28            }
29            _ => None,
30        }
31    }
32}
33
34#[derive(Debug, Clone)]
35pub struct ProcessResult {
36    pub code: i64,
37    pub stdout: String,
38    pub stderr: String,
39}
40
41impl ProcessResult {
42    pub fn get_attr(&self, name: &str) -> Option<Value> {
43        match name {
44            "code" => Some(Value::Int(self.code)),
45            "stdout" => Some(Value::String(Arc::new(self.stdout.clone()))),
46            "stderr" => Some(Value::String(Arc::new(self.stderr.clone()))),
47            _ => None,
48        }
49    }
50}