teo_runtime/struct/object/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::collections::BTreeMap;
use std::fmt::{Display, Formatter};
use std::sync::{Arc, Mutex};
use serde::{Serialize, Serializer};
use crate::value::Value;

#[derive(Debug, Clone)]
pub struct Object {
    inner: Arc<ObjectInner>
}

impl Object {

    pub fn new(struct_path: Vec<String>, fields: BTreeMap<String, Value>) -> Self {
        Self {
            inner: Arc::new(ObjectInner {
                struct_path,
                fields: Mutex::new(fields),
            })
        }
    }

    pub fn struct_path(&self) -> Vec<&str> {
        self.inner.as_ref().struct_path.iter().map(AsRef::as_ref).collect()
    }
}

impl Serialize for Object {

    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
        serializer.serialize_none()
    }
}

#[derive(Debug)]
struct ObjectInner {
    struct_path: Vec<String>,
    fields: Mutex<BTreeMap<String, Value>>
}

impl Display for Object {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str(&self.inner.struct_path.join("."))
    }
}