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,25 @@ 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
- /// mod my_object {
22
+ /// mod ffi {
18
23
/// #[cxx_qt::qobject]
19
24
/// #[derive(Default)]
20
- /// struct RustObj {
25
+ /// pub struct MyObject {
21
26
/// #[qproperty]
22
27
/// property: i32,
23
28
/// }
24
29
///
25
- /// impl qobject::RustObj {
30
+ /// impl qobject::MyObject {
26
31
/// #[qinvokable]
27
32
/// fn invokable(&self, a: i32, b: i32) -> i32 {
28
33
/// a + b
29
34
/// }
30
35
/// }
31
36
/// }
37
+ ///
38
+ /// # fn main() {}
32
39
/// ```
33
40
#[ proc_macro_attribute]
34
41
pub fn bridge ( args : TokenStream , input : TokenStream ) -> TokenStream {
@@ -58,14 +65,20 @@ pub fn bridge(args: TokenStream, input: TokenStream) -> TokenStream {
58
65
///
59
66
/// # Example
60
67
///
61
- /// ```ignore
62
- /// #[cxx_qt::bridge(namespace = "cxx_qt::my_object") ]
68
+ /// ```rust
69
+ /// #[cxx_qt::bridge]
63
70
/// mod my_object {
71
+ /// #[cxx_qt::qobject]
72
+ /// #[derive(Default)]
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
+ /// # fn main() {}
69
82
/// ```
70
83
#[ proc_macro_attribute]
71
84
pub fn qsignals ( _args : TokenStream , _input : TokenStream ) -> TokenStream {
@@ -78,28 +91,34 @@ pub fn qsignals(_args: TokenStream, _input: TokenStream) -> TokenStream {
78
91
///
79
92
/// # Example
80
93
///
81
- /// ```ignore
82
- /// #[cxx_qt::bridge(namespace = "cxx_qt::my_object") ]
94
+ /// ```rust
95
+ /// #[cxx_qt::bridge]
83
96
/// mod my_object {
84
97
/// #[cxx_qt::qobject]
85
- /// struct MyObject;
98
+ /// #[derive(Default)]
99
+ /// pub struct MyObject;
86
100
/// }
101
+ ///
102
+ /// # fn main() {}
87
103
/// ```
88
104
///
89
105
/// 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
106
///
91
107
/// # Example
92
108
///
93
- /// ```ignore
94
- /// #[cxx_qt::bridge(namespace = "cxx_qt::my_object") ]
109
+ /// ```rust
110
+ /// #[cxx_qt::bridge]
95
111
/// mod my_object {
96
112
/// #[cxx_qt::qobject(base = "QStringListModel")]
97
- /// struct MyModel;
113
+ /// #[derive(Default)]
114
+ /// pub struct MyModel;
98
115
///
99
116
/// unsafe extern "C++" {
100
117
/// include!(<QtCore/QStringListModel>);
101
118
/// }
102
119
/// }
120
+ ///
121
+ /// # fn main() {}
103
122
/// ```
104
123
#[ proc_macro_attribute]
105
124
pub fn qobject ( _args : TokenStream , _input : TokenStream ) -> TokenStream {
@@ -114,25 +133,32 @@ pub fn qobject(_args: TokenStream, _input: TokenStream) -> TokenStream {
114
133
/// details.
115
134
///
116
135
/// # Example
117
- /// ``` ignore
136
+ /// ``` rust
118
137
/// #[cxx_qt::bridge]
119
138
/// mod my_object {
139
+ /// extern "C++" {
140
+ /// include!("cxx-qt-lib/qmodelindex.h");
141
+ /// type QModelIndex = cxx_qt_lib::QModelIndex;
142
+ /// }
143
+ ///
120
144
/// #[cxx_qt::qobject(base="QAbstractListModel")]
121
145
/// #[derive(Default)]
122
- /// struct MyObject;
146
+ /// pub struct MyObject;
123
147
///
124
148
/// #[cxx_qt::inherit]
125
149
/// extern "C++" {
126
150
/// // Unsafe to call
127
- /// unsafe fn begin_insert_rows(self: Pin<&mut Self >, parent: &QModelIndex, first: i32, last: i32);
151
+ /// unsafe fn begin_insert_rows(self: Pin<&mut qobject::MyObject >, parent: &QModelIndex, first: i32, last: i32);
128
152
/// }
129
153
///
130
154
/// #[cxx_qt::inherit]
131
155
/// unsafe extern "C++" {
132
156
/// // Safe to call - you are responsible to ensure this is true!
133
- /// fn end_insert_rows(self: Pin<&mut Self >);
157
+ /// fn end_insert_rows(self: Pin<&mut qobject::MyObject >);
134
158
/// }
135
159
/// }
160
+ ///
161
+ /// # fn main() {}
136
162
/// ```
137
163
#[ proc_macro_attribute]
138
164
pub fn inherit ( _args : TokenStream , _input : TokenStream ) -> TokenStream {
0 commit comments