gir_parser/
callback.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    Stability,
11};
12
13#[derive(Clone, Debug, XmlDeserialize)]
14#[xmlserde(root = b"callback")]
15#[xmlserde(deny_unknown_fields)]
16pub struct Callback {
17    #[xmlserde(name = b"name", ty = "attr")]
18    name: String,
19    #[xmlserde(name = b"c:type", ty = "attr")]
20    c_type: Option<String>,
21    #[xmlserde(name = b"throws", ty = "attr")]
22    throws: Option<bool>,
23    // Common attributes
24    #[xmlserde(name = b"introspectable", ty = "attr")]
25    introspectable: Option<bool>,
26    #[xmlserde(name = b"deprecated", ty = "attr")]
27    deprecated: Option<bool>,
28    #[xmlserde(name = b"version", ty = "attr")]
29    version: Option<Version>,
30    #[xmlserde(name = b"deprecated-version", ty = "attr")]
31    deprecated_version: Option<Version>,
32    #[xmlserde(name = b"stability", ty = "attr")]
33    stability: Option<Stability>,
34    // Documentation
35    #[xmlserde(name = b"doc", ty = "child")]
36    doc: Option<Documentation>,
37    #[xmlserde(name = b"doc-deprecated", ty = "child")]
38    doc_deprecated: Option<DocDeprecated>,
39    #[xmlserde(name = b"doc-stability", ty = "child")]
40    doc_stability: Option<DocStability>,
41    #[xmlserde(name = b"doc-version", ty = "child")]
42    doc_version: Option<DocVersion>,
43    #[xmlserde(name = b"source-position", ty = "child")]
44    source_position: Option<SourcePosition>,
45    // Attributes: 0 or more
46    #[xmlserde(name = b"attribute", ty = "child")]
47    attributes: Vec<Attribute>,
48    #[xmlserde(name = b"return-value", ty = "child")]
49    return_value: ReturnValue,
50    #[xmlserde(name = b"parameters", ty = "child", default = "Parameters::default")]
51    parameters: Parameters,
52}
53
54impl Callback {
55    pub fn name(&self) -> &str {
56        &self.name
57    }
58
59    pub fn c_type(&self) -> Option<&str> {
60        self.c_type.as_deref()
61    }
62}
63
64impl_info!(Callback);
65impl_attributable!(Callback);
66impl_documentable!(Callback);
67impl_function_like!(Callback);