specta/datatype/
object.rs1use crate::{DataType, NamedDataType, NamedDataTypeItem};
2
3#[derive(Debug, Clone, PartialEq)]
5#[allow(missing_docs)]
6pub struct ObjectField {
7 pub key: &'static str,
8 pub optional: bool,
9 pub flatten: bool,
10 pub ty: DataType,
11}
12
13#[derive(Debug, Clone, PartialEq, Default)]
16#[allow(missing_docs)]
17pub struct ObjectType {
18 pub generics: Vec<&'static str>,
19 pub fields: Vec<ObjectField>,
20 pub tag: Option<&'static str>,
21}
22
23impl ObjectType {
24 pub fn to_anonymous(self) -> DataType {
26 DataType::Object(self)
27 }
28
29 pub fn to_named(self, name: &'static str) -> NamedDataType {
33 NamedDataType {
34 name,
35 sid: None,
36 impl_location: None,
37 comments: &[],
38 export: None,
39 deprecated: None,
40 item: NamedDataTypeItem::Object(self),
41 }
42 }
43}
44
45impl From<ObjectType> for DataType {
46 fn from(t: ObjectType) -> Self {
47 t.to_anonymous()
48 }
49}