gir_parser/
signal.rs

1use xmlserde_derives::XmlDeserialize;
2
3use crate::{
4    attribute::Attribute,
5    documentation::{DocDeprecated, DocStability, DocVersion, Documentation, SourcePosition},
6    parameter::Parameters,
7    prelude::*,
8    return_value::ReturnValue,
9    version::Version,
10    SignalEmission, Stability,
11};
12
13#[derive(Clone, Debug, XmlDeserialize)]
14#[xmlserde(root = b"glib:signal")]
15#[xmlserde(deny_unknown_fields)]
16pub struct Signal {
17    #[xmlserde(name = b"name", ty = "attr")]
18    name: String,
19    #[xmlserde(name = b"detailed", ty = "attr")]
20    detailed: Option<bool>,
21    #[xmlserde(name = b"when", ty = "attr")]
22    when: Option<SignalEmission>,
23    #[xmlserde(name = b"action", ty = "attr")]
24    action: Option<bool>,
25    #[xmlserde(name = b"no-hooks", ty = "attr")]
26    no_hooks: Option<bool>,
27    #[xmlserde(name = b"no-recurse", ty = "attr")]
28    no_recurse: Option<bool>,
29    #[xmlserde(name = b"emitter", ty = "attr")]
30    emitter: Option<String>,
31    // Common attributes
32    #[xmlserde(name = b"introspectable", ty = "attr")]
33    introspectable: Option<bool>,
34    #[xmlserde(name = b"deprecated", ty = "attr")]
35    deprecated: Option<bool>,
36    #[xmlserde(name = b"version", ty = "attr")]
37    version: Option<Version>,
38    #[xmlserde(name = b"deprecated-version", ty = "attr")]
39    deprecated_version: Option<Version>,
40    #[xmlserde(name = b"stability", ty = "attr")]
41    stability: Option<Stability>,
42    // Documentation
43    #[xmlserde(name = b"doc", ty = "child")]
44    doc: Option<Documentation>,
45    #[xmlserde(name = b"doc-deprecated", ty = "child")]
46    doc_deprecated: Option<DocDeprecated>,
47    #[xmlserde(name = b"doc-stability", ty = "child")]
48    doc_stability: Option<DocStability>,
49    #[xmlserde(name = b"doc-version", ty = "child")]
50    doc_version: Option<DocVersion>,
51    #[xmlserde(name = b"source-position", ty = "child")]
52    source_position: Option<SourcePosition>,
53    // Attributes: 0 or more
54    #[xmlserde(name = b"attribute", ty = "child")]
55    attributes: Vec<Attribute>,
56
57    #[xmlserde(name = b"return-value", ty = "child")]
58    return_value: ReturnValue,
59    #[xmlserde(name = b"parameters", ty = "child", default = "Parameters::default")]
60    parameters: Parameters,
61}
62
63impl Signal {
64    pub fn name(&self) -> &str {
65        &self.name
66    }
67
68    pub fn is_detailed(&self) -> bool {
69        self.detailed.unwrap_or(false)
70    }
71
72    pub fn when(&self) -> Option<SignalEmission> {
73        self.when
74    }
75
76    pub fn is_action(&self) -> bool {
77        self.action.unwrap_or(false)
78    }
79
80    pub fn is_no_hooks(&self) -> bool {
81        self.no_hooks.unwrap_or(false)
82    }
83
84    pub fn is_no_recurse(&self) -> bool {
85        self.no_recurse.unwrap_or(false)
86    }
87
88    pub fn emitter(&self) -> Option<&str> {
89        self.emitter.as_deref()
90    }
91
92    pub fn return_value(&self) -> &ReturnValue {
93        &self.return_value
94    }
95
96    pub fn parameters(&self) -> &Parameters {
97        &self.parameters
98    }
99}
100
101impl_info!(Signal);
102impl_attributable!(Signal);
103impl_documentable!(Signal);