From 05b677834fc9ddc71f22cacb6742f32e0ac6f631 Mon Sep 17 00:00:00 2001 From: Julian Hofer Date: Fri, 12 Jul 2024 13:49:04 +0200 Subject: [PATCH] book: cargo fmt --- book/listings/actions/2/main.rs | 10 ++++--- book/listings/main_event_loop/4/main.rs | 36 +++++++++++++++++-------- book/listings/main_event_loop/5/main.rs | 18 ++++++++----- book/listings/main_event_loop/6/main.rs | 30 ++++++++++++--------- book/listings/main_event_loop/8/main.rs | 15 ++++++++--- book/listings/main_event_loop/9/main.rs | 15 ++++++++--- 6 files changed, 82 insertions(+), 42 deletions(-) diff --git a/book/listings/actions/2/main.rs b/book/listings/actions/2/main.rs index c060b847c453..524530d8f76b 100644 --- a/book/listings/actions/2/main.rs +++ b/book/listings/actions/2/main.rs @@ -32,9 +32,13 @@ fn build_ui(app: &Application) { // Add action "close" to `window` taking no parameter let action_close = ActionEntry::builder("close") - .activate(clone!(#[weak] window, move |_, _, _| { - window.close(); - })) + .activate(clone!( + #[weak] + window, + move |_, _, _| { + window.close(); + } + )) .build(); // ANCHOR: action_group diff --git a/book/listings/main_event_loop/4/main.rs b/book/listings/main_event_loop/4/main.rs index 804e71a4a121..723757336f0a 100644 --- a/book/listings/main_event_loop/4/main.rs +++ b/book/listings/main_event_loop/4/main.rs @@ -30,21 +30,35 @@ fn build_ui(app: &Application) { let (sender, receiver) = async_channel::bounded(1); // Connect to "clicked" signal of `button` button.connect_clicked(move |_| { - glib::spawn_future_local(clone!(#[strong] sender, async move { - // Deactivate the button until the operation is done - sender.send(false).await.expect("The channel needs to be open."); - glib::timeout_future_seconds(5).await; - // Activate the button again - sender.send(true).await.expect("The channel needs to be open."); - })); + glib::spawn_future_local(clone!( + #[strong] + sender, + async move { + // Deactivate the button until the operation is done + sender + .send(false) + .await + .expect("The channel needs to be open."); + glib::timeout_future_seconds(5).await; + // Activate the button again + sender + .send(true) + .await + .expect("The channel needs to be open."); + } + )); }); // The main loop executes the asynchronous block - glib::spawn_future_local(clone!(#[weak] button, async move { - while let Ok(enable_button) = receiver.recv().await { - button.set_sensitive(enable_button); + glib::spawn_future_local(clone!( + #[weak] + button, + async move { + while let Ok(enable_button) = receiver.recv().await { + button.set_sensitive(enable_button); + } } - })); + )); // ANCHOR_END: callback // Create a window diff --git a/book/listings/main_event_loop/5/main.rs b/book/listings/main_event_loop/5/main.rs index c3ec9f9475ed..b773cb3f020a 100644 --- a/book/listings/main_event_loop/5/main.rs +++ b/book/listings/main_event_loop/5/main.rs @@ -28,13 +28,17 @@ fn build_ui(app: &Application) { // ANCHOR: callback // Connect to "clicked" signal of `button` button.connect_clicked(move |button| { - glib::spawn_future_local(clone!(#[weak] button, async move { - // Deactivate the button until the operation is done - button.set_sensitive(false); - glib::timeout_future_seconds(5).await; - // Activate the button again - button.set_sensitive(true); - })); + glib::spawn_future_local(clone!( + #[weak] + button, + async move { + // Deactivate the button until the operation is done + button.set_sensitive(false); + glib::timeout_future_seconds(5).await; + // Activate the button again + button.set_sensitive(true); + } + )); }); // ANCHOR_END: callback diff --git a/book/listings/main_event_loop/6/main.rs b/book/listings/main_event_loop/6/main.rs index 03dc260dce0d..69c92dddac3e 100644 --- a/book/listings/main_event_loop/6/main.rs +++ b/book/listings/main_event_loop/6/main.rs @@ -32,19 +32,23 @@ fn build_ui(app: &Application) { // Connect to "clicked" signal of `button` button.connect_clicked(move |button| { // The main loop executes the asynchronous block - glib::spawn_future_local(clone!(#[weak] button, async move { - // Deactivate the button until the operation is done - button.set_sensitive(false); - let enable_button = gio::spawn_blocking(move || { - let five_seconds = Duration::from_secs(5); - thread::sleep(five_seconds); - true - }) - .await - .expect("Task needs to finish successfully."); - // Set sensitivity of button to `enable_button` - button.set_sensitive(enable_button); - })); + glib::spawn_future_local(clone!( + #[weak] + button, + async move { + // Deactivate the button until the operation is done + button.set_sensitive(false); + let enable_button = gio::spawn_blocking(move || { + let five_seconds = Duration::from_secs(5); + thread::sleep(five_seconds); + true + }) + .await + .expect("Task needs to finish successfully."); + // Set sensitivity of button to `enable_button` + button.set_sensitive(enable_button); + } + )); }); // ANCHOR_END: callback diff --git a/book/listings/main_event_loop/8/main.rs b/book/listings/main_event_loop/8/main.rs index e329faa19480..08c0752ba2a8 100644 --- a/book/listings/main_event_loop/8/main.rs +++ b/book/listings/main_event_loop/8/main.rs @@ -31,10 +31,17 @@ fn build_ui(app: &Application) { // Connect to "clicked" signal of `button` button.connect_clicked(move |_| { // The main loop executes the asynchronous block - glib::spawn_future_local(clone!(#[strong] sender, async move { - let response = reqwest::get("https://www.gtk-rs.org").await; - sender.send(response).await.expect("The channel needs to be open."); - })); + glib::spawn_future_local(clone!( + #[strong] + sender, + async move { + let response = reqwest::get("https://www.gtk-rs.org").await; + sender + .send(response) + .await + .expect("The channel needs to be open."); + } + )); }); // The main loop executes the asynchronous block diff --git a/book/listings/main_event_loop/9/main.rs b/book/listings/main_event_loop/9/main.rs index 42b74041fec1..ba0fbdef20a2 100644 --- a/book/listings/main_event_loop/9/main.rs +++ b/book/listings/main_event_loop/9/main.rs @@ -42,10 +42,17 @@ fn build_ui(app: &Application) { let (sender, receiver) = async_channel::bounded(1); // Connect to "clicked" signal of `button` button.connect_clicked(move |_| { - runtime().spawn(clone!(#[strong] sender, async move { - let response = reqwest::get("https://www.gtk-rs.org").await; - sender.send(response).await.expect("The channel needs to be open."); - })); + runtime().spawn(clone!( + #[strong] + sender, + async move { + let response = reqwest::get("https://www.gtk-rs.org").await; + sender + .send(response) + .await + .expect("The channel needs to be open."); + } + )); }); // The main loop executes the asynchronous block