4
4
//
5
5
// SPDX-License-Identifier: MIT OR Apache-2.0
6
6
7
- #![ deny( missing_docs) ]
7
+ // We explicitly allow missing docs for the macros in this crate, as they should be documented in
8
+ // cxx-qt itself.
9
+ #![ allow( missing_docs) ]
8
10
//! The cxx-qt-macro crate provides the procedural attribute macros which are used with cxx-qt.
11
+ //!
12
+ //! See the [cxx-qt crate docs](https://docs.rs/cxx-qt/latest/) for documentation of the macros
13
+ //! inside this crate.
9
14
10
15
use proc_macro:: TokenStream ;
11
16
use syn:: { parse_macro_input, ItemMod } ;
12
17
13
18
use cxx_qt_gen:: { write_rust, GeneratedRustBlocks , Parser } ;
14
19
15
- /// A procedural macro which generates a QObject for a struct inside a module.
16
- ///
17
- /// # Example
18
- ///
19
- /// ```rust
20
- /// #[cxx_qt::bridge(namespace = "cxx_qt::my_object")]
21
- /// mod qobject {
22
- /// extern "RustQt" {
23
- /// #[qobject]
24
- /// # // Note that we can't use properties as this confuses the linker on Windows
25
- /// type MyObject = super::MyObjectRust;
26
- ///
27
- /// #[qinvokable]
28
- /// fn invokable(self: &MyObject, a: i32, b: i32) -> i32;
29
- /// }
30
- /// }
31
- ///
32
- /// #[derive(Default)]
33
- /// pub struct MyObjectRust;
34
- ///
35
- /// impl qobject::MyObject {
36
- /// fn invokable(&self, a: i32, b: i32) -> i32 {
37
- /// a + b
38
- /// }
39
- /// }
40
- ///
41
- /// # // Note that we need a fake main for doc tests to build
42
- /// # fn main() {
43
- /// # cxx_qt::init_crate!(cxx_qt);
44
- /// # }
45
- /// ```
46
20
#[ proc_macro_attribute]
47
21
pub fn bridge ( args : TokenStream , input : TokenStream ) -> TokenStream {
48
22
// Parse the TokenStream of a macro
@@ -65,65 +39,11 @@ pub fn bridge(args: TokenStream, input: TokenStream) -> TokenStream {
65
39
extract_and_generate ( module)
66
40
}
67
41
68
- /// A macro which describes that a struct should be made into a QObject.
69
- ///
70
- /// It should not be used by itself and instead should be used inside a cxx_qt::bridge definition.
71
- ///
72
- /// # Example
73
- ///
74
- /// ```rust
75
- /// #[cxx_qt::bridge]
76
- /// mod my_object {
77
- /// extern "RustQt" {
78
- /// #[qobject]
79
- /// # // Note that we can't use properties as this confuses the linker on Windows
80
- /// type MyObject = super::MyObjectRust;
81
- /// }
82
- /// }
83
- ///
84
- /// #[derive(Default)]
85
- /// pub struct MyObjectRust;
86
- ///
87
- /// # // Note that we need a fake main for doc tests to build
88
- /// # fn main() {
89
- /// # cxx_qt::init_crate!(cxx_qt);
90
- /// # }
91
- /// ```
92
- ///
93
- /// You can also specify a custom base class by using `#[base = QStringListModel]`, you must then use CXX to add any includes needed.
94
- ///
95
- /// # Example
96
- ///
97
- /// ```rust
98
- /// #[cxx_qt::bridge]
99
- /// mod my_object {
100
- /// extern "RustQt" {
101
- /// #[qobject]
102
- /// #[base = QStringListModel]
103
- /// # // Note that we can't use properties as this confuses the linker on Windows
104
- /// type MyModel = super::MyModelRust;
105
- /// }
106
- ///
107
- /// unsafe extern "C++" {
108
- /// include!(<QtCore/QStringListModel>);
109
- /// type QStringListModel;
110
- /// }
111
- /// }
112
- ///
113
- /// #[derive(Default)]
114
- /// pub struct MyModelRust;
115
- ///
116
- /// # // Note that we need a fake main for doc tests to build
117
- /// # fn main() {
118
- /// # cxx_qt::init_crate!(cxx_qt);
119
- /// # }
120
- /// ```
121
42
#[ proc_macro_attribute]
122
43
pub fn qobject ( _args : TokenStream , _input : TokenStream ) -> TokenStream {
123
44
unreachable ! ( "qobject should not be used as a macro by itself. Instead it should be used within a cxx_qt::bridge definition" )
124
45
}
125
46
126
- /// Force a crate to be initialized
127
47
#[ proc_macro]
128
48
pub fn init_crate ( args : TokenStream ) -> TokenStream {
129
49
let crate_name = syn:: parse_macro_input!( args as syn:: Ident ) ;
@@ -137,7 +57,6 @@ pub fn init_crate(args: TokenStream) -> TokenStream {
137
57
. into ( )
138
58
}
139
59
140
- /// Force a QML module with the given URI to be initialized
141
60
#[ proc_macro]
142
61
pub fn init_qml_module ( args : TokenStream ) -> TokenStream {
143
62
let module_uri = syn:: parse_macro_input!( args as syn:: LitStr ) ;
0 commit comments