1use xmlserde_derives::XmlDeserialize;
2
3use crate::{
4 attribute::Attribute,
5 documentation::{DocDeprecated, DocStability, DocVersion, Documentation, SourcePosition},
6 field::Field,
7 function::{Function, FunctionInline},
8 method::{Method, MethodInline},
9 prelude::*,
10 union::Union,
11 version::Version,
12 Callback, Stability,
13};
14
15#[derive(Clone, Debug, XmlDeserialize)]
16#[allow(clippy::large_enum_variant)]
19pub enum RecordField {
20 #[xmlserde(name = b"field")]
21 Field(Field),
22 #[xmlserde(name = b"union")]
23 Union(Union),
24 #[xmlserde(name = b"record")]
25 Record(Record),
26 #[xmlserde(name = b"callback")]
27 Callback(Callback),
28}
29
30#[derive(Clone, Debug, XmlDeserialize)]
31#[xmlserde(root = b"record")]
32#[xmlserde(deny_unknown_fields)]
33pub struct Record {
34 #[xmlserde(name = b"name", ty = "attr")]
35 name: Option<String>,
36 #[xmlserde(name = b"c:type", ty = "attr")]
37 c_type: Option<String>,
38 #[xmlserde(name = b"disguised", ty = "attr")]
40 disguised: Option<bool>,
41 #[xmlserde(name = b"pointer", ty = "attr")]
42 pointer: Option<bool>,
43 #[xmlserde(name = b"opaque", ty = "attr")]
44 opaque: Option<bool>,
45 #[xmlserde(name = b"foreign", ty = "attr")]
46 foreign: Option<bool>,
47 #[xmlserde(name = b"glib:is-gtype-struct-for", ty = "attr")]
48 g_is_gtype_struct_for: Option<String>,
49 #[xmlserde(name = b"glib:type-name", ty = "attr")]
50 g_type_name: Option<String>,
51 #[xmlserde(name = b"glib:get-type", ty = "attr")]
52 g_get_type: Option<String>,
53 #[xmlserde(name = b"c:symbol-prefix", ty = "attr")]
54 symbol_prefix: Option<String>,
55 #[xmlserde(name = b"copy-function", ty = "attr")]
56 copy_function: Option<String>,
57 #[xmlserde(name = b"free-function", ty = "attr")]
58 free_function: Option<String>,
59
60 #[xmlserde(name = b"introspectable", ty = "attr")]
62 introspectable: Option<bool>,
63 #[xmlserde(name = b"deprecated", ty = "attr")]
64 deprecated: Option<bool>,
65 #[xmlserde(name = b"version", ty = "attr")]
66 version: Option<Version>,
67 #[xmlserde(name = b"deprecated-version", ty = "attr")]
68 deprecated_version: Option<Version>,
69 #[xmlserde(name = b"stability", ty = "attr")]
70 stability: Option<Stability>,
71 #[xmlserde(name = b"doc", ty = "child")]
73 doc: Option<Documentation>,
74 #[xmlserde(name = b"doc-deprecated", ty = "child")]
75 doc_deprecated: Option<DocDeprecated>,
76 #[xmlserde(name = b"doc-stability", ty = "child")]
77 doc_stability: Option<DocStability>,
78 #[xmlserde(name = b"doc-version", ty = "child")]
79 doc_version: Option<DocVersion>,
80 #[xmlserde(name = b"source-position", ty = "child")]
81 source_position: Option<SourcePosition>,
82 #[xmlserde(name = b"attribute", ty = "child")]
84 attributes: Vec<Attribute>,
85
86 #[xmlserde(name = b"constructor", ty = "child")]
87 constructors: Vec<Function>,
88 #[xmlserde(name = b"function", ty = "child")]
89 functions: Vec<Function>,
90 #[xmlserde(name = b"function-inline", ty = "child")]
91 inline_functions: Vec<FunctionInline>,
92
93 #[xmlserde(name = b"method", ty = "child")]
94 methods: Vec<Method>,
95 #[xmlserde(name = b"inline-methods", ty = "child")]
96 inline_methods: Vec<MethodInline>,
97
98 #[xmlserde(ty = "untag")]
99 fields: Vec<RecordField>,
100}
101
102impl Record {
103 pub fn name(&self) -> Option<&str> {
104 self.name.as_deref()
105 }
106
107 pub fn c_type(&self) -> Option<&str> {
108 self.c_type.as_deref()
109 }
110
111 pub fn is_disguised(&self) -> bool {
112 self.disguised.unwrap_or(false)
113 }
114
115 pub fn is_opaque(&self) -> bool {
116 self.opaque.unwrap_or(false)
117 }
118
119 pub fn is_pointer(&self) -> bool {
120 self.pointer.unwrap_or(false)
121 }
122
123 pub fn is_foreign(&self) -> bool {
124 self.foreign.unwrap_or(false)
125 }
126
127 pub fn g_is_gtype_struct_for(&self) -> Option<&str> {
128 self.g_is_gtype_struct_for.as_deref()
129 }
130
131 pub fn g_type_name(&self) -> Option<&str> {
132 self.g_type_name.as_deref()
133 }
134
135 pub fn g_get_type(&self) -> Option<&str> {
136 self.g_get_type.as_deref()
137 }
138
139 pub fn symbol_prefix(&self) -> Option<&str> {
140 self.symbol_prefix.as_deref()
141 }
142
143 pub fn copy_function(&self) -> Option<&str> {
144 self.copy_function.as_deref()
145 }
146
147 pub fn free_function(&self) -> Option<&str> {
148 self.free_function.as_deref()
149 }
150
151 pub fn fields(&self) -> &[RecordField] {
152 &self.fields
153 }
154
155 pub fn methods(&self) -> &[Method] {
156 &self.methods
157 }
158
159 pub fn inlined_methods(&self) -> &[MethodInline] {
160 &self.inline_methods
161 }
162
163 pub fn functions(&self) -> &[Function] {
164 &self.functions
165 }
166
167 pub fn inlined_functions(&self) -> &[FunctionInline] {
168 &self.inline_functions
169 }
170
171 pub fn constructors(&self) -> &[Function] {
172 &self.constructors
173 }
174}
175
176impl_info!(Record);
177impl_attributable!(Record);
178impl_documentable!(Record);