Calling multiple mutable functions (e.g. signals) on Pin<&mut T>
#1015
-
Hi there, First of all, thanks for your quick responses to two questions I posted recently. I'm slowly getting the hang of it. I am wondering how to emit two signals in a row in a Rust-safe manner. Given:
The Rust compiler will complain on emitting the second signal, because both signals take a Pinned mutable reference and this cannot be copied: Edit: call me a Rust noob (I am), but I haven´t even found an unsafe way to do this in Rust. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @SanderVocke , this is a common question we get that stems from Rusts somewhat suboptimal TL;DR:Use
Long-winded explanation:Functions that take a Pinned mutable reference usually take But as Pin is just a "normal" struct that contains a reference, it will consume the struct itself (i.e. the Pin). That is what As It's unfortunate that you always have to do this explicitly, but that's how Rust has implemented this at the moment. |
Beta Was this translation helpful? Give feedback.
Yes you would need the implementation to have marked
self
as mutableYou can see an example of this here
cxx-qt/examples/qml_features/rust/src/threading.rs
Line 85 in 78554ec
fetch_title
with amut
thenas_mut()
is used within the functioncxx-qt/examples/qml_features/rust/src/threading.rs
Line 103 in 78554ec
Note how the CXX bridge part does not need this
mut
cxx-qt/examples/qml_features/rust/src/threading.rs
Lin…