1use xmlserde_derives::XmlDeserialize;
2
3use crate::{
4 attribute::Attribute,
5 documentation::{DocDeprecated, DocStability, DocVersion, Documentation, SourcePosition},
6 function::{Function, FunctionInline},
7 member::Member,
8 prelude::*,
9 version::Version,
10 Stability,
11};
12
13#[derive(Clone, Debug, PartialEq, Eq, XmlDeserialize)]
14#[xmlserde(root = b"enumeration")]
15#[xmlserde(deny_unknown_fields)]
16pub struct Enumeration {
17 #[xmlserde(name = b"name", ty = "attr")]
18 name: String,
19 #[xmlserde(name = b"c:type", ty = "attr")]
20 c_type: String,
21 #[xmlserde(name = b"glib:type-name", ty = "attr")]
22 g_type_name: Option<String>,
23 #[xmlserde(name = b"glib:get-type", ty = "attr")]
24 g_get_type: Option<String>,
25 #[xmlserde(name = b"glib:error-domain", ty = "attr")]
26 g_error_domain: Option<String>,
27 #[xmlserde(name = b"introspectable", ty = "attr")]
29 introspectable: Option<bool>,
30 #[xmlserde(name = b"deprecated", ty = "attr")]
31 deprecated: Option<bool>,
32 #[xmlserde(name = b"version", ty = "attr")]
33 version: Option<Version>,
34 #[xmlserde(name = b"deprecated-version", ty = "attr")]
35 deprecated_version: Option<Version>,
36 #[xmlserde(name = b"stability", ty = "attr")]
37 stability: Option<Stability>,
38 #[xmlserde(name = b"doc", ty = "child")]
40 doc: Option<Documentation>,
41 #[xmlserde(name = b"doc-deprecated", ty = "child")]
42 doc_deprecated: Option<DocDeprecated>,
43 #[xmlserde(name = b"doc-stability", ty = "child")]
44 doc_stability: Option<DocStability>,
45 #[xmlserde(name = b"doc-version", ty = "child")]
46 doc_version: Option<DocVersion>,
47 #[xmlserde(name = b"source-position", ty = "child")]
48 source_position: Option<SourcePosition>,
49 #[xmlserde(name = b"attribute", ty = "child")]
51 attributes: Vec<Attribute>,
52 #[xmlserde(name = b"member", ty = "child")]
54 members: Vec<Member>,
55 #[xmlserde(name = b"function", ty = "child")]
57 functions: Vec<Function>,
58 #[xmlserde(name = b"function-inline", ty = "child")]
59 inline_functions: Vec<FunctionInline>,
60}
61
62impl Enumeration {
63 pub fn name(&self) -> &str {
64 &self.name
65 }
66
67 pub fn c_type(&self) -> &str {
68 &self.c_type
69 }
70
71 pub fn g_type_name(&self) -> Option<&str> {
72 self.g_type_name.as_deref()
73 }
74
75 pub fn g_get_type(&self) -> Option<&str> {
76 self.g_get_type.as_deref()
77 }
78
79 pub fn g_error_domain(&self) -> Option<&str> {
80 self.g_error_domain.as_deref()
81 }
82
83 pub fn members(&self) -> &[Member] {
84 &self.members
85 }
86
87 pub fn functions(&self) -> &[Function] {
88 &self.functions
89 }
90
91 pub fn inlined_functions(&self) -> &[FunctionInline] {
92 &self.inline_functions
93 }
94}
95
96impl_info!(Enumeration);
97impl_attributable!(Enumeration);
98impl_documentable!(Enumeration);
99
100impl IntoIterator for Enumeration {
101 type Item = Member;
102 type IntoIter = std::vec::IntoIter<Self::Item>;
103
104 fn into_iter(self) -> Self::IntoIter {
105 self.members.into_iter()
106 }
107}
108
109impl<'a> IntoIterator for &'a Enumeration {
110 type Item = &'a Member;
111 type IntoIter = std::slice::Iter<'a, Member>;
112
113 fn into_iter(self) -> Self::IntoIter {
114 self.members.iter()
115 }
116}
117
118impl AsRef<[Member]> for Enumeration {
119 fn as_ref(&self) -> &[Member] {
120 &self.members
121 }
122}
123
124impl std::ops::Deref for Enumeration {
125 type Target = [Member];
126
127 fn deref(&self) -> &Self::Target {
128 &self.members
129 }
130}
131
132impl std::ops::Index<usize> for Enumeration {
133 type Output = Member;
134
135 fn index(&self, index: usize) -> &Self::Output {
136 &self.members[index]
137 }
138}