Skip to content

Commit 99ee9ad

Browse files
committed
cxx-qt: activate doctests for the macros and deny missing docs in the crate
Related to #21
1 parent fbe4d03 commit 99ee9ad

File tree

2 files changed

+56
-19
lines changed

2 files changed

+56
-19
lines changed

crates/cxx-qt/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ proc-macro = true
2323
cxx-qt-gen.workspace = true
2424
proc-macro2.workspace = true
2525
syn.workspace = true
26+
27+
[dev-dependencies]
28+
cxx.workspace = true
29+
cxx-qt-lib.workspace = true

crates/cxx-qt/src/lib.rs

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
// SPDX-FileContributor: Gerhard de Clercq <[email protected]>
44
//
55
// 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+
611
use proc_macro::TokenStream;
712
use syn::{parse_macro_input, ItemMod};
813

@@ -12,23 +17,24 @@ use cxx_qt_gen::{write_rust, GeneratedRustBlocks, Parser};
1217
///
1318
/// # Example
1419
///
15-
/// ```ignore
20+
/// ```rust
1621
/// #[cxx_qt::bridge(namespace = "cxx_qt::my_object")]
1722
/// mod my_object {
1823
/// #[cxx_qt::qobject]
1924
/// #[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;
2427
///
25-
/// impl qobject::RustObj {
28+
/// impl qobject::MyObject {
2629
/// #[qinvokable]
2730
/// fn invokable(&self, a: i32, b: i32) -> i32 {
2831
/// a + b
2932
/// }
3033
/// }
3134
/// }
35+
///
36+
/// # // Note that we need a fake main for doc tests to build
37+
/// # fn main() {}
3238
/// ```
3339
#[proc_macro_attribute]
3440
pub fn bridge(args: TokenStream, input: TokenStream) -> TokenStream {
@@ -58,14 +64,22 @@ pub fn bridge(args: TokenStream, input: TokenStream) -> TokenStream {
5864
///
5965
/// # Example
6066
///
61-
/// ```ignore
62-
/// #[cxx_qt::bridge(namespace = "cxx_qt::my_object")]
67+
/// ```rust
68+
/// #[cxx_qt::bridge]
6369
/// 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+
///
6475
/// #[cxx_qt::qsignals(MyObject)]
65-
/// enum MySignals {
76+
/// pub enum MySignals {
6677
/// Ready,
6778
/// }
6879
/// }
80+
///
81+
/// # // Note that we need a fake main for doc tests to build
82+
/// # fn main() {}
6983
/// ```
7084
#[proc_macro_attribute]
7185
pub fn qsignals(_args: TokenStream, _input: TokenStream) -> TokenStream {
@@ -78,28 +92,38 @@ pub fn qsignals(_args: TokenStream, _input: TokenStream) -> TokenStream {
7892
///
7993
/// # Example
8094
///
81-
/// ```ignore
82-
/// #[cxx_qt::bridge(namespace = "cxx_qt::my_object")]
95+
/// ```rust
96+
/// #[cxx_qt::bridge]
8397
/// mod my_object {
8498
/// #[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;
86102
/// }
103+
///
104+
/// # // Note that we need a fake main for doc tests to build
105+
/// # fn main() {}
87106
/// ```
88107
///
89108
/// 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.
90109
///
91110
/// # Example
92111
///
93-
/// ```ignore
94-
/// #[cxx_qt::bridge(namespace = "cxx_qt::my_object")]
112+
/// ```rust
113+
/// #[cxx_qt::bridge]
95114
/// mod my_object {
96115
/// #[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;
98119
///
99120
/// unsafe extern "C++" {
100121
/// include!(<QtCore/QStringListModel>);
101122
/// }
102123
/// }
124+
///
125+
/// # // Note that we need a fake main for doc tests to build
126+
/// # fn main() {}
103127
/// ```
104128
#[proc_macro_attribute]
105129
pub fn qobject(_args: TokenStream, _input: TokenStream) -> TokenStream {
@@ -114,25 +138,34 @@ pub fn qobject(_args: TokenStream, _input: TokenStream) -> TokenStream {
114138
/// details.
115139
///
116140
/// # Example
117-
/// ``` ignore
141+
/// ``` rust
118142
/// #[cxx_qt::bridge]
119143
/// mod my_object {
144+
/// extern "C++" {
145+
/// include!("cxx-qt-lib/qmodelindex.h");
146+
/// type QModelIndex = cxx_qt_lib::QModelIndex;
147+
/// }
148+
///
120149
/// #[cxx_qt::qobject(base="QAbstractListModel")]
121150
/// #[derive(Default)]
122-
/// struct MyObject;
151+
/// # // Note that we can't use properties as this confuses the linker on Windows
152+
/// pub struct MyObject;
123153
///
124154
/// #[cxx_qt::inherit]
125155
/// extern "C++" {
126156
/// // 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);
128158
/// }
129159
///
130160
/// #[cxx_qt::inherit]
131161
/// unsafe extern "C++" {
132162
/// // 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>);
134164
/// }
135165
/// }
166+
///
167+
/// # // Note that we need a fake main for doc tests to build
168+
/// # fn main() {}
136169
/// ```
137170
#[proc_macro_attribute]
138171
pub fn inherit(_args: TokenStream, _input: TokenStream) -> TokenStream {

0 commit comments

Comments
 (0)