how to take ownership from state? #12611
-
i use state to manage a oneshot sender: let (send,recv) = oneshot::channel::<()>();
app.manage(send); but when i want to use the sender to send a message, thie is some error: #[tauri::command]
pub fn exit_app(send:State<'_, Sender<()>) {
send.send(()).expect("send error");
exit(0)
} the #[tauri::command]
pub fn exit_app(send:State<'_, Mutex<Sender<()>>>) {
(send.lock().unwrap()).send(()).expect("send error");
exit(0)
} i also try #[tauri::command]
pub fn exit_app<'r>(mut send:State<'r, Option<Sender<()>>>) {
let option = send.take();
option.unwrap().send(()).expect("send error");
exit(0)
} but it also error:error[E0596]: cannot borrow data in dereference of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You were really close actually! If you combine your last 2 tries into |
Beta Was this translation helpful? Give feedback.
You were really close actually! If you combine your last 2 tries into
Mutex<Option<Sender>>
it should work