3
3
// SPDX-FileContributor: Gerhard de Clercq <[email protected] >
4
4
//
5
5
// SPDX-License-Identifier: MIT OR Apache-2.0
6
+
7
+ #![ deny( missing_docs) ]
8
+
9
+ //! The cxx-qt crate provides the procedural attribute macros which are used with cxx-qt.
10
+
6
11
use proc_macro:: TokenStream ;
7
12
use syn:: { parse_macro_input, ItemMod } ;
8
13
@@ -12,23 +17,24 @@ use cxx_qt_gen::{write_rust, GeneratedRustBlocks, Parser};
12
17
///
13
18
/// # Example
14
19
///
15
- /// ```ignore
20
+ /// ```rust
16
21
/// #[cxx_qt::bridge(namespace = "cxx_qt::my_object")]
17
22
/// mod my_object {
18
23
/// #[cxx_qt::qobject]
19
24
/// #[derive(Default)]
20
- /// struct RustObj {
21
- /// #[qproperty]
22
- /// property: i32,
23
- /// }
25
+ /// # // Note that we can't use properties as this confuses the linker on Windows
26
+ /// pub struct MyObject;
24
27
///
25
- /// impl qobject::RustObj {
28
+ /// impl qobject::MyObject {
26
29
/// #[qinvokable]
27
30
/// fn invokable(&self, a: i32, b: i32) -> i32 {
28
31
/// a + b
29
32
/// }
30
33
/// }
31
34
/// }
35
+ ///
36
+ /// # // Note that we need a fake main for doc tests to build
37
+ /// # fn main() {}
32
38
/// ```
33
39
#[ proc_macro_attribute]
34
40
pub fn bridge ( args : TokenStream , input : TokenStream ) -> TokenStream {
@@ -58,14 +64,22 @@ pub fn bridge(args: TokenStream, input: TokenStream) -> TokenStream {
58
64
///
59
65
/// # Example
60
66
///
61
- /// ```ignore
62
- /// #[cxx_qt::bridge(namespace = "cxx_qt::my_object") ]
67
+ /// ```rust
68
+ /// #[cxx_qt::bridge]
63
69
/// mod my_object {
70
+ /// #[cxx_qt::qobject]
71
+ /// #[derive(Default)]
72
+ /// # // Note that we can't use properties as this confuses the linker on Windows
73
+ /// pub struct MyObject;
74
+ ///
64
75
/// #[cxx_qt::qsignals(MyObject)]
65
- /// enum MySignals {
76
+ /// pub enum MySignals {
66
77
/// Ready,
67
78
/// }
68
79
/// }
80
+ ///
81
+ /// # // Note that we need a fake main for doc tests to build
82
+ /// # fn main() {}
69
83
/// ```
70
84
#[ proc_macro_attribute]
71
85
pub fn qsignals ( _args : TokenStream , _input : TokenStream ) -> TokenStream {
@@ -78,28 +92,38 @@ pub fn qsignals(_args: TokenStream, _input: TokenStream) -> TokenStream {
78
92
///
79
93
/// # Example
80
94
///
81
- /// ```ignore
82
- /// #[cxx_qt::bridge(namespace = "cxx_qt::my_object") ]
95
+ /// ```rust
96
+ /// #[cxx_qt::bridge]
83
97
/// mod my_object {
84
98
/// #[cxx_qt::qobject]
85
- /// struct MyObject;
99
+ /// #[derive(Default)]
100
+ /// # // Note that we can't use properties as this confuses the linker on Windows
101
+ /// pub struct MyObject;
86
102
/// }
103
+ ///
104
+ /// # // Note that we need a fake main for doc tests to build
105
+ /// # fn main() {}
87
106
/// ```
88
107
///
89
108
/// You can also specify a custom base class by using `#[cxx_qt::qobject(base = "QStringListModel")]`, you must then use CXX to add any includes needed.
90
109
///
91
110
/// # Example
92
111
///
93
- /// ```ignore
94
- /// #[cxx_qt::bridge(namespace = "cxx_qt::my_object") ]
112
+ /// ```rust
113
+ /// #[cxx_qt::bridge]
95
114
/// mod my_object {
96
115
/// #[cxx_qt::qobject(base = "QStringListModel")]
97
- /// struct MyModel;
116
+ /// #[derive(Default)]
117
+ /// # // Note that we can't use properties as this confuses the linker on Windows
118
+ /// pub struct MyModel;
98
119
///
99
120
/// unsafe extern "C++" {
100
121
/// include!(<QtCore/QStringListModel>);
101
122
/// }
102
123
/// }
124
+ ///
125
+ /// # // Note that we need a fake main for doc tests to build
126
+ /// # fn main() {}
103
127
/// ```
104
128
#[ proc_macro_attribute]
105
129
pub fn qobject ( _args : TokenStream , _input : TokenStream ) -> TokenStream {
@@ -114,25 +138,34 @@ pub fn qobject(_args: TokenStream, _input: TokenStream) -> TokenStream {
114
138
/// details.
115
139
///
116
140
/// # Example
117
- /// ``` ignore
141
+ /// ``` rust
118
142
/// #[cxx_qt::bridge]
119
143
/// mod my_object {
144
+ /// extern "C++" {
145
+ /// include!("cxx-qt-lib/qmodelindex.h");
146
+ /// type QModelIndex = cxx_qt_lib::QModelIndex;
147
+ /// }
148
+ ///
120
149
/// #[cxx_qt::qobject(base="QAbstractListModel")]
121
150
/// #[derive(Default)]
122
- /// struct MyObject;
151
+ /// # // Note that we can't use properties as this confuses the linker on Windows
152
+ /// pub struct MyObject;
123
153
///
124
154
/// #[cxx_qt::inherit]
125
155
/// extern "C++" {
126
156
/// // Unsafe to call
127
- /// unsafe fn begin_insert_rows(self: Pin<&mut Self >, parent: &QModelIndex, first: i32, last: i32);
157
+ /// unsafe fn begin_insert_rows(self: Pin<&mut qobject::MyObject >, parent: &QModelIndex, first: i32, last: i32);
128
158
/// }
129
159
///
130
160
/// #[cxx_qt::inherit]
131
161
/// unsafe extern "C++" {
132
162
/// // Safe to call - you are responsible to ensure this is true!
133
- /// fn end_insert_rows(self: Pin<&mut Self >);
163
+ /// fn end_insert_rows(self: Pin<&mut qobject::MyObject >);
134
164
/// }
135
165
/// }
166
+ ///
167
+ /// # // Note that we need a fake main for doc tests to build
168
+ /// # fn main() {}
136
169
/// ```
137
170
#[ proc_macro_attribute]
138
171
pub fn inherit ( _args : TokenStream , _input : TokenStream ) -> TokenStream {
0 commit comments