1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright (C) 2026 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only
use QMetaObject;
use crateDispatchMetaCall;
use crateDynamicMetaObjectData;
use Rc;
use RefCell;
use Pin;
/// `QCppProxy` defines what a C++ proxy to a QObject (C++) must implement.
///
/// This includes access to the C++ static meta-object, which is then extended
/// on the Rust side to create a dynamic meta-object.
/// `QRustProxy` defines the Rust-side bridge object that binds:
///
/// - A Rust object stored in `Rc<RefCell<dyn _>>`
/// - A corresponding C++ QObject-based proxy
///
/// Implementations of this trait are the concrete glue layer between
/// Rust and Qt, usually using Cxx.
///
/// # Purpose
///
/// A `QRustProxy` implementation:
///
/// - Stores a raw pointer to the C++ proxy (`cpp_proxy`)
/// - Stores access to the Rust object through `RustObjAccess<dyn _>` (`rust_obj`)
/// - Coordinates destruction, layout and Qt meta-object information
/// - Forwards all foreign function calls to the C++ proxy
///
/// Typical structure:
///
/// ```rust, ignore
/// pub struct QObjectProxyRust {
/// cpp_proxy: *mut QObjectProxyCpp,
/// rust_obj: RustObjAccess<dyn QObjectProxyGet>,
/// on_drop: fn(rust_obj: *const u8),
/// }
/// ```
///
/// Where:
///
/// - `cpp_proxy` points to the actual C++ QObject subclass.
/// - `rust_obj` wraps access to the users rust object.
/// - `on_drop` cleaning up memory.
///
/// # Lifetime and Ownership
///
/// A `QRustProxy` instance is heap-allocated and owned through a raw pointer, because its
/// lifetime is jointly managed with C++ code and the C++ side requires a stable, non-movable
/// address.
///
/// Destruction is always initiated from the C++ side: the paired `CppProxy` destructor calls
/// [`GenericRustProxy::drop_self`], which converts the raw pointer back to a `Box`, invokes
/// the stored `on_drop` callback, and then drops this instance along with its reference to the
/// Rust object.
///
/// The reference held to the user's Rust object is either strong (`Rc`) or weak (`Weak`),
/// depending on the [`ConstructionMode`] passed to [`QRustProxy::new`]:
///
/// - `Strong` / `AtAddress` - proxy holds a strong `Rc`; the proxy pair keeps the Rust object
/// alive (QML-created / OwnedByQml path).
/// - `Weak` - proxy holds only a `Weak` reference; the Rust `Rc` controls the struct's lifetime
/// (Rust-created / OwnedByRust path).
///
/// # Associated Types
///
/// ## `ProxyCppType`
///
/// The concrete C++ proxy type. Has to implement [`QCppProxy`].
///
/// ## `AdapterType`
///
/// A wrapper trait for the interface trait that QtBridge users implement. This wrapper
/// is required because not all traits can be used with dyn and are thus incompatible with
/// `RustObjAccess` (See "object safety" or "dyn compatibility").
///