Skip to content

Commit 35c25cd

Browse files
committed
cxx-qt: activate doctests for the macros and deny missing docs in the crate
Related to KDAB#21
1 parent 0f8d04c commit 35c25cd

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
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: 43 additions & 17 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,25 @@ 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")]
17-
/// mod my_object {
22+
/// mod ffi {
1823
/// #[cxx_qt::qobject]
1924
/// #[derive(Default)]
20-
/// struct RustObj {
25+
/// pub struct MyObject {
2126
/// #[qproperty]
2227
/// property: i32,
2328
/// }
2429
///
25-
/// impl qobject::RustObj {
30+
/// impl qobject::MyObject {
2631
/// #[qinvokable]
2732
/// fn invokable(&self, a: i32, b: i32) -> i32 {
2833
/// a + b
2934
/// }
3035
/// }
3136
/// }
37+
///
38+
/// # fn main() {}
3239
/// ```
3340
#[proc_macro_attribute]
3441
pub fn bridge(args: TokenStream, input: TokenStream) -> TokenStream {
@@ -58,14 +65,20 @@ pub fn bridge(args: TokenStream, input: TokenStream) -> TokenStream {
5865
///
5966
/// # Example
6067
///
61-
/// ```ignore
62-
/// #[cxx_qt::bridge(namespace = "cxx_qt::my_object")]
68+
/// ```rust
69+
/// #[cxx_qt::bridge]
6370
/// mod my_object {
71+
/// #[cxx_qt::qobject]
72+
/// #[derive(Default)]
73+
/// pub struct MyObject;
74+
///
6475
/// #[cxx_qt::qsignals(MyObject)]
65-
/// enum MySignals {
76+
/// pub enum MySignals {
6677
/// Ready,
6778
/// }
6879
/// }
80+
///
81+
/// # fn main() {}
6982
/// ```
7083
#[proc_macro_attribute]
7184
pub fn qsignals(_args: TokenStream, _input: TokenStream) -> TokenStream {
@@ -78,28 +91,34 @@ pub fn qsignals(_args: TokenStream, _input: TokenStream) -> TokenStream {
7891
///
7992
/// # Example
8093
///
81-
/// ```ignore
82-
/// #[cxx_qt::bridge(namespace = "cxx_qt::my_object")]
94+
/// ```rust
95+
/// #[cxx_qt::bridge]
8396
/// mod my_object {
8497
/// #[cxx_qt::qobject]
85-
/// struct MyObject;
98+
/// #[derive(Default)]
99+
/// pub struct MyObject;
86100
/// }
101+
///
102+
/// # fn main() {}
87103
/// ```
88104
///
89105
/// 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.
90106
///
91107
/// # Example
92108
///
93-
/// ```ignore
94-
/// #[cxx_qt::bridge(namespace = "cxx_qt::my_object")]
109+
/// ```rust
110+
/// #[cxx_qt::bridge]
95111
/// mod my_object {
96112
/// #[cxx_qt::qobject(base = "QStringListModel")]
97-
/// struct MyModel;
113+
/// #[derive(Default)]
114+
/// pub struct MyModel;
98115
///
99116
/// unsafe extern "C++" {
100117
/// include!(<QtCore/QStringListModel>);
101118
/// }
102119
/// }
120+
///
121+
/// # fn main() {}
103122
/// ```
104123
#[proc_macro_attribute]
105124
pub fn qobject(_args: TokenStream, _input: TokenStream) -> TokenStream {
@@ -114,25 +133,32 @@ pub fn qobject(_args: TokenStream, _input: TokenStream) -> TokenStream {
114133
/// details.
115134
///
116135
/// # Example
117-
/// ``` ignore
136+
/// ``` rust
118137
/// #[cxx_qt::bridge]
119138
/// mod my_object {
139+
/// extern "C++" {
140+
/// include!("cxx-qt-lib/qmodelindex.h");
141+
/// type QModelIndex = cxx_qt_lib::QModelIndex;
142+
/// }
143+
///
120144
/// #[cxx_qt::qobject(base="QAbstractListModel")]
121145
/// #[derive(Default)]
122-
/// struct MyObject;
146+
/// pub struct MyObject;
123147
///
124148
/// #[cxx_qt::inherit]
125149
/// extern "C++" {
126150
/// // 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);
128152
/// }
129153
///
130154
/// #[cxx_qt::inherit]
131155
/// unsafe extern "C++" {
132156
/// // 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>);
134158
/// }
135159
/// }
160+
///
161+
/// # fn main() {}
136162
/// ```
137163
#[proc_macro_attribute]
138164
pub fn inherit(_args: TokenStream, _input: TokenStream) -> TokenStream {

0 commit comments

Comments
 (0)