teo_runtime/interface/field/
field.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use std::collections::BTreeMap;
use serde::Serialize;
use teo_parser::r#type::Type;
use crate::comment::Comment;
use crate::model::field::is_optional::{IsOptional};
use crate::model::field::typed::Typed;
use crate::optionality::Optionality;
use crate::traits::documentable::Documentable;
use crate::traits::named::Named;
use crate::Value;

#[derive(Debug, Serialize, Clone)]
pub struct Field {
    pub(super) name: String,
    pub(super) comment: Option<Comment>,
    pub(super) r#type: Type,
    pub(super) optionality: Optionality,
    pub(super) data: BTreeMap<String, Value>,
}

impl Field {

    pub fn name(&self) -> &str {
        self.name.as_str()
    }

    pub fn comment(&self) -> Option<&Comment> {
        self.comment.as_ref()
    }

    pub fn r#type(&self) -> &Type {
        &self.r#type
    }

    pub fn optionality(&self) -> &Optionality {
        &self.optionality
    }

    pub fn data(&self) -> &BTreeMap<String, Value> {
        &self.data
    }
}

impl IsOptional for Field {

    fn is_optional(&self) -> bool {
        self.optionality.is_any_optional()
    }

    fn is_required(&self) -> bool {
        self.optionality.is_required()
    }
}

impl Named for Field {

    fn name(&self) -> &str {
        self.name.as_str()
    }
}

impl Documentable for Field {

    fn comment(&self) -> Option<&Comment> {
        self.comment.as_ref()
    }

    fn kind(&self) -> &'static str {
        "interface field"
    }
}

impl Typed for Field {

    fn r#type(&self) -> &Type {
        &self.r#type
    }
}