-
my pub fn main() {
let mongodb_url = std::sync::Arc::new(std::sync::Mutex::new(String::default()));
let app = App::new();
app.on_mongodb_url_edited({
let mongodb_url = mongodb_url.clone();
move |text| {
println!("edited:{}", text);
let mut mongodb_url = mongodb_url.lock().unwrap();
*mongodb_url = text.to_string();
}
});
app.on_mongodb_url_clicked({
let mongodb_url = mongodb_url.clone();
move || {
let mongodb_url = mongodb_url.lock().unwrap();
println!("clicked:{}", mongodb_url);
}
});
app.run();
} my
Does this mean that I need a lock for all the interactions between the UI and the application logic? Also, because the application is running inside |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I'm not sure I understand the question, but our code looks correct, yes.
Sort of, yes. |
Beta Was this translation helpful? Give feedback.
I'm not sure I understand the question, but our code looks correct, yes.
If you want to share
mongodb_url
to another thread, it needs to be in aArc<Mutex<...>>
Sort of, yes.
The UI is in the main thread, and all your callback and functions are going to be run in that thread.
If your logic is in a
Arc<Mutex<..>>
you indeed need to lock it.