mold_cli/types/
object.rs

1use super::field::Field;
2use super::schema::SchemaType;
3
4#[derive(Debug, Clone, PartialEq)]
5pub struct ObjectType {
6    pub fields: Vec<Field>,
7}
8
9impl ObjectType {
10    pub fn new(fields: Vec<Field>) -> Self {
11        Self { fields }
12    }
13
14    pub fn empty() -> Self {
15        Self { fields: vec![] }
16    }
17}
18
19#[derive(Debug, Clone)]
20pub struct NestedType {
21    pub name: String,
22    pub object: ObjectType,
23}
24
25impl NestedType {
26    pub fn new(name: impl Into<String>, object: ObjectType) -> Self {
27        Self {
28            name: name.into(),
29            object,
30        }
31    }
32}
33
34#[derive(Debug, Clone)]
35pub struct Schema {
36    pub name: String,
37    pub root_type: SchemaType,
38    pub nested_types: Vec<NestedType>,
39}
40
41impl Schema {
42    pub fn new(name: impl Into<String>, root_type: SchemaType) -> Self {
43        Self {
44            name: name.into(),
45            root_type,
46            nested_types: vec![],
47        }
48    }
49
50    pub fn with_nested_types(mut self, nested_types: Vec<NestedType>) -> Self {
51        self.nested_types = nested_types;
52        self
53    }
54}