pub trait QRustProxy {
type ProxyCppType;
type AdapterType: ?Sized;
// Required methods
fn new<OnDropFn: FnOnce() + 'static>(
rust_obj: &Rc<RefCell<Self::AdapterType>>,
construction: ConstructionMode,
on_drop: OnDropFn,
) -> *mut Self;
fn get_static_meta_object() -> &'static QMetaObject;
fn get_size_of_cpp_proxy() -> usize;
fn get_align_of_cpp_proxy() -> usize;
fn get_qmetatype_list_of_cpp_proxy() -> QMetaType;
fn get_cpp_proxy(&self) -> *const Self::ProxyCppType;
fn get_cpp_proxy_mut(&self) -> *mut Self::ProxyCppType;
}Expand description
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:
ⓘ
pub struct QObjectProxyRust {
cpp_proxy: *mut QObjectProxyCpp,
rust_obj: RustObjAccess<dyn QObjectProxyGet>,
on_drop: fn(rust_obj: *const u8),
}Where:
cpp_proxypoints to the actual C++ QObject subclass.rust_objwraps access to the users rust object.on_dropcleaning up memory.
§Associated Types
§ProxyCppType
The concrete C++ proxy type.
§RcRefCellType
The Rust container type holding the actual object, typically:
ⓘ
Rc<RefCell<dyn MarkerTrait>>The MarkerTrait is implemented on the users rust struct by the qobject macro.
Required Associated Types§
type ProxyCppType
type AdapterType: ?Sized
Required Methods§
fn new<OnDropFn: FnOnce() + 'static>( rust_obj: &Rc<RefCell<Self::AdapterType>>, construction: ConstructionMode, on_drop: OnDropFn, ) -> *mut Self
fn get_static_meta_object() -> &'static QMetaObject
fn get_size_of_cpp_proxy() -> usize
fn get_align_of_cpp_proxy() -> usize
fn get_qmetatype_list_of_cpp_proxy() -> QMetaType
fn get_cpp_proxy(&self) -> *const Self::ProxyCppType
fn get_cpp_proxy_mut(&self) -> *mut Self::ProxyCppType
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.