Skip to content

Commit 31a4312

Browse files
Improve docs
1 parent dbdcdbd commit 31a4312

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

crates/cxx-qt/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ pub trait Threading: Sized {
217217
}
218218

219219
#[doc(hidden)]
220+
// This is implemented when using `impl cxx_qt::Constructor<...> for ... {}` and allows Constructor to be implemented.
221+
// This is done with a trait bound on `Constructor` which avoids declaring constructors outside the bridge which aren't actually used.
220222
pub trait ConstructorDeclared<Arguments> {}
221223

222224
/// This trait can be implemented on any [CxxQtType] to define a
@@ -226,10 +228,13 @@ pub trait ConstructorDeclared<Arguments> {}
226228
///
227229
/// If this trait is implemented for a given [CxxQtType], it must also be declared inside the
228230
/// [cxx_qt::bridge](bridge) macro.
231+
/// Under the hood, this works by implementing a shim trait called [ConstructorDeclared].
232+
/// If this is not present, you cannot use your constructor, so if you encounter an error regarding this trait,
233+
/// it is most likely you have forgotten to declare your constructor inside the bridge.
229234
/// See the example below.
230235
///
231236
/// Note that declaring an implementation of this trait will stop CXX-Qt from generating a default constructor.
232-
/// Therefore an implementation of [Default] is no longer required for the Rust type.
237+
/// Therefore, an implementation of [Default] is no longer required for the Rust type.
233238
///
234239
/// # Minimal Example
235240
///
@@ -241,7 +246,9 @@ pub trait ConstructorDeclared<Arguments> {}
241246
/// type MyStruct = super::MyStructRust;
242247
/// }
243248
///
244-
/// // Declare that we want to use a custom constructor
249+
/// // Declare that we want to use a custom constructor,
250+
/// // which will implement `ConstructorDeclared` for these particular args.
251+
/// //
245252
/// // Note that the arguments must be a tuple of CXX types.
246253
/// // Any associated types that aren't included here are assumed to be `()`.
247254
/// impl cxx_qt::Constructor<(i32, String), NewArguments=(i32, String)> for MyStruct {}
@@ -253,6 +260,7 @@ pub trait ConstructorDeclared<Arguments> {}
253260
/// pub string: String
254261
/// }
255262
///
263+
/// // After declaring we want a custom constructor in the bridge, we must implement it.
256264
/// impl cxx_qt::Constructor<(i32, String)> for qobject::MyStruct {
257265
/// type BaseArguments = (); // Will be passed to the base class constructor
258266
/// type InitializeArguments = (); // Will be passed to the "initialize" function

0 commit comments

Comments
 (0)