Skip to content

Commit 54559b7

Browse files
committed
cxx-qt: move connection guard inside cxx-qt from lib
1 parent 09df480 commit 54559b7

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

crates/cxx-qt-lib/src/core/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ pub use qmargins::QMargins;
3838
mod qmarginsf;
3939
pub use qmarginsf::QMarginsF;
4040

41-
// Reexport QMetaObject connection from cxx-qt
42-
pub use cxx_qt::QMetaObjectConnection;
43-
44-
mod qmetaobjectconnectionguard;
45-
pub use qmetaobjectconnectionguard::QMetaObjectConnectionGuard;
41+
// Reexport QMetaObject connection and guard from cxx-qt
42+
pub use cxx_qt::{QMetaObjectConnection, QMetaObjectConnectionGuard};
4643

4744
mod qmodelindex;
4845
pub use qmodelindex::QModelIndex;

crates/cxx-qt/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() {
1313
qt_build_utils::setup_linker();
1414

1515
let cpp_files = ["src/cxxqt_connection.cpp"];
16-
let rust_bridges = ["src/connection.rs"];
16+
let rust_bridges = ["src/connection.rs", "src/connectionguard.rs"];
1717

1818
for bridge in &rust_bridges {
1919
println!("cargo:rerun-if-changed={bridge}");

crates/cxx-qt-lib/src/core/qmetaobjectconnectionguard.rs renamed to crates/cxx-qt/src/connectionguard.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

6+
use crate::QMetaObjectConnection;
7+
68
#[cxx::bridge]
79
mod ffi {
810
extern "Rust" {
@@ -13,17 +15,17 @@ mod ffi {
1315

1416
/// Represents a guard to a signal-slot (or signal-functor) connection.
1517
///
16-
/// This struct can be created from a [cxx_qt::QMetaObjectConnection].
18+
/// This struct can be created from a [QMetaObjectConnection].
1719
///
1820
/// Note that when this struct is dropped the connection is disconnected.
1921
/// So to keep a connection active either hold onto the struct for the duration
2022
/// that the connection should be active or call `release`.
2123
pub struct QMetaObjectConnectionGuard {
22-
connection: cxx_qt::QMetaObjectConnection,
24+
connection: QMetaObjectConnection,
2325
}
2426

25-
impl From<cxx_qt::QMetaObjectConnection> for QMetaObjectConnectionGuard {
26-
fn from(connection: cxx_qt::QMetaObjectConnection) -> Self {
27+
impl From<QMetaObjectConnection> for QMetaObjectConnectionGuard {
28+
fn from(connection: QMetaObjectConnection) -> Self {
2729
Self { connection }
2830
}
2931
}
@@ -37,7 +39,7 @@ impl Drop for QMetaObjectConnectionGuard {
3739

3840
impl QMetaObjectConnectionGuard {
3941
/// Release the connection without disconnecting
40-
pub fn release(mut self) -> cxx_qt::QMetaObjectConnection {
42+
pub fn release(mut self) -> QMetaObjectConnection {
4143
// Take the connection as our Drop implementation disconnects automatically
4244
// whereas we just want to release
4345
core::mem::take(&mut self.connection)

crates/cxx-qt/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use std::{fs::File, io::Write, path::Path};
1313

1414
mod connection;
15+
mod connectionguard;
1516
#[doc(hidden)]
1617
pub mod signalhandler;
1718
mod threading;
@@ -20,6 +21,7 @@ pub use cxx_qt_macro::bridge;
2021
pub use cxx_qt_macro::qobject;
2122

2223
pub use connection::{ConnectionType, QMetaObjectConnection};
24+
pub use connectionguard::QMetaObjectConnectionGuard;
2325
pub use threading::CxxQtThread;
2426

2527
// Export static assertions that can then be used in cxx-qt-gen generation

0 commit comments

Comments
 (0)