gir_parser/
property.rs

1use xmlserde_derives::XmlDeserialize;
2
3use crate::{
4    attribute::Attribute,
5    documentation::{DocDeprecated, DocStability, DocVersion, Documentation, SourcePosition},
6    prelude::*,
7    version::Version,
8    AnyType, Stability, TransferOwnership,
9};
10
11#[derive(Clone, Debug, XmlDeserialize)]
12#[xmlserde(root = b"property")]
13#[xmlserde(deny_unknown_fields)]
14pub struct Property {
15    #[xmlserde(name = b"name", ty = "attr")]
16    name: String,
17    #[xmlserde(name = b"readable", ty = "attr")]
18    readable: Option<bool>,
19    #[xmlserde(name = b"writable", ty = "attr")]
20    writable: Option<bool>,
21    #[xmlserde(name = b"construct", ty = "attr")]
22    construct: Option<bool>,
23    #[xmlserde(name = b"construct-only", ty = "attr")]
24    construct_only: Option<bool>,
25    #[xmlserde(name = b"setter", ty = "attr")]
26    setter: Option<String>,
27    #[xmlserde(name = b"getter", ty = "attr")]
28    getter: Option<String>,
29    #[xmlserde(name = b"default-value", ty = "attr")]
30    default_value: Option<String>,
31    #[xmlserde(name = b"transfer-ownership", ty = "attr")]
32    transfer_ownership: Option<TransferOwnership>,
33    // Common attributes
34    #[xmlserde(name = b"introspectable", ty = "attr")]
35    introspectable: Option<bool>,
36    #[xmlserde(name = b"deprecated", ty = "attr")]
37    deprecated: Option<bool>,
38    #[xmlserde(name = b"version", ty = "attr")]
39    version: Option<Version>,
40    #[xmlserde(name = b"deprecated-version", ty = "attr")]
41    deprecated_version: Option<Version>,
42    #[xmlserde(name = b"stability", ty = "attr")]
43    stability: Option<Stability>,
44    // Documentation
45    #[xmlserde(name = b"doc", ty = "child")]
46    doc: Option<Documentation>,
47    #[xmlserde(name = b"doc-deprecated", ty = "child")]
48    doc_deprecated: Option<DocDeprecated>,
49    #[xmlserde(name = b"doc-stability", ty = "child")]
50    doc_stability: Option<DocStability>,
51    #[xmlserde(name = b"doc-version", ty = "child")]
52    doc_version: Option<DocVersion>,
53    #[xmlserde(name = b"source-position", ty = "child")]
54    source_position: Option<SourcePosition>,
55    // Attributes: 0 or more
56    #[xmlserde(name = b"attribute", ty = "child")]
57    attributes: Vec<Attribute>,
58    #[xmlserde(name = b"type", ty = "child")]
59    type_: AnyType,
60}
61
62impl Property {
63    pub fn name(&self) -> &str {
64        &self.name
65    }
66
67    pub fn is_readable(&self) -> bool {
68        self.readable.unwrap_or(true)
69    }
70
71    pub fn is_writable(&self) -> bool {
72        self.writable.unwrap_or(false)
73    }
74
75    pub fn is_construct(&self) -> bool {
76        self.construct.unwrap_or(false)
77    }
78
79    pub fn is_construct_only(&self) -> bool {
80        self.construct_only.unwrap_or(false)
81    }
82
83    pub fn transfer_ownership(&self) -> TransferOwnership {
84        self.transfer_ownership.unwrap_or(TransferOwnership::None)
85    }
86
87    pub fn getter(&self) -> Option<&str> {
88        self.getter.as_deref()
89    }
90
91    pub fn setter(&self) -> Option<&str> {
92        self.setter.as_deref()
93    }
94
95    pub fn default_value(&self) -> Option<&str> {
96        self.default_value.as_deref()
97    }
98
99    pub fn ty(&self) -> &AnyType {
100        &self.type_
101    }
102}
103
104impl_info!(Property);
105impl_documentable!(Property);
106impl_attributable!(Property);