Skip to content

Commit 88dcd64

Browse files
authored
Update book to new clone! syntax (#1795)
* book: Rename config to config.toml * book: Use new `clone!` syntax * Small formatting changes * book: Adapt inline listing * book: Fix link * book: cargo fmt * Use latest ashpd release
1 parent f0f553d commit 88dcd64

File tree

24 files changed

+837
-762
lines changed

24 files changed

+837
-762
lines changed
File renamed without changes.

book/listings/Cargo.lock

Lines changed: 438 additions & 542 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

book/listings/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ edition = "2021"
55

66

77
[dependencies]
8-
adw = { version = "0.6", package = "libadwaita", features = ["v1_5"] }
8+
adw = { version = "0.7", package = "libadwaita", features = ["v1_5"] }
99
anyhow = "1.0"
10-
ashpd = { version = "0.8", features = ["gtk4"] }
10+
ashpd = { version = "0.9", features = ["gtk4"] }
1111
async-channel = "2.0"
1212
dirs = "5.0"
13-
gtk = { version = "0.8", package = "gtk4", features = ["v4_12"] }
13+
gtk = { version = "0.9", package = "gtk4", features = ["v4_12"] }
1414
reqwest = { version = "0.12", default-features = false, features = [
1515
"rustls-tls",
1616
] }
@@ -21,7 +21,7 @@ walkdir = "2.3"
2121
xshell = "0.2"
2222

2323
[build-dependencies]
24-
glib-build-tools = "0.19"
24+
glib-build-tools = "0.20"
2525

2626
# actions
2727
[[bin]]

book/listings/actions/2/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ fn build_ui(app: &Application) {
3232

3333
// Add action "close" to `window` taking no parameter
3434
let action_close = ActionEntry::builder("close")
35-
.activate(clone!(@weak window => move |_, _, _| {
36-
window.close();
37-
}))
35+
.activate(clone!(
36+
#[weak]
37+
window,
38+
move |_, _, _| {
39+
window.close();
40+
}
41+
))
3842
.build();
3943

4044
// ANCHOR: action_group

book/listings/g_object_memory_management/3/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ fn build_ui(app: &Application) {
3939
// Connect callbacks
4040
// When a button is clicked, `number` will be changed
4141
// ANCHOR: callback
42-
button_increase.connect_clicked(clone!(@strong number => move |_| {
43-
number.set(number.get() + 1);
44-
}));
42+
button_increase.connect_clicked(clone!(
43+
#[strong]
44+
number,
45+
move |_| {
46+
number.set(number.get() + 1);
47+
}
48+
));
4549
button_decrease.connect_clicked(move |_| {
4650
number.set(number.get() - 1);
4751
});

book/listings/g_object_memory_management/4/main.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,24 @@ fn build_ui(app: &Application) {
4040
// ANCHOR: callback
4141
// Connect callbacks
4242
// When a button is clicked, `number` and label of the other button will be changed
43-
button_increase.connect_clicked(clone!(@weak number, @strong button_decrease =>
43+
button_increase.connect_clicked(clone!(
44+
#[weak]
45+
number,
46+
#[strong]
47+
button_decrease,
4448
move |_| {
4549
number.set(number.get() + 1);
4650
button_decrease.set_label(&number.get().to_string());
47-
}));
48-
button_decrease.connect_clicked(clone!(@strong button_increase =>
51+
}
52+
));
53+
button_decrease.connect_clicked(clone!(
54+
#[strong]
55+
button_increase,
4956
move |_| {
5057
number.set(number.get() - 1);
5158
button_increase.set_label(&number.get().to_string());
52-
}));
59+
}
60+
));
5361
// ANCHOR_END: callback
5462

5563
// Add buttons to `gtk_box`

book/listings/g_object_memory_management/5/main.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,24 @@ fn build_ui(app: &Application) {
4141
// ANCHOR: callback
4242
// Connect callbacks
4343
// When a button is clicked, `number` and label of the other button will be changed
44-
button_increase.connect_clicked(clone!(@weak number, @weak button_decrease =>
44+
button_increase.connect_clicked(clone!(
45+
#[weak]
46+
number,
47+
#[weak]
48+
button_decrease,
4549
move |_| {
4650
number.set(number.get() + 1);
4751
button_decrease.set_label(&number.get().to_string());
48-
}));
49-
button_decrease.connect_clicked(clone!(@weak button_increase =>
52+
}
53+
));
54+
button_decrease.connect_clicked(clone!(
55+
#[weak]
56+
button_increase,
5057
move |_| {
5158
number.set(number.get() - 1);
5259
button_increase.set_label(&number.get().to_string());
53-
}));
60+
}
61+
));
5462
// ANCHOR_END: callback
5563

5664
// ANCHOR: box_append

book/listings/main_event_loop/3/main.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ fn build_ui(app: &Application) {
5050
});
5151

5252
// The main loop executes the asynchronous block
53-
glib::spawn_future_local(clone!(@weak button => async move {
54-
while let Ok(enable_button) = receiver.recv().await {
55-
button.set_sensitive(enable_button);
53+
glib::spawn_future_local(clone!(
54+
#[weak]
55+
button,
56+
async move {
57+
while let Ok(enable_button) = receiver.recv().await {
58+
button.set_sensitive(enable_button);
59+
}
5660
}
57-
}));
61+
));
5862
// ANCHOR_END: callback
5963

6064
// Create a window

book/listings/main_event_loop/4/main.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,35 @@ fn build_ui(app: &Application) {
3030
let (sender, receiver) = async_channel::bounded(1);
3131
// Connect to "clicked" signal of `button`
3232
button.connect_clicked(move |_| {
33-
glib::spawn_future_local(clone!(@strong sender => async move {
34-
// Deactivate the button until the operation is done
35-
sender.send(false).await.expect("The channel needs to be open.");
36-
glib::timeout_future_seconds(5).await;
37-
// Activate the button again
38-
sender.send(true).await.expect("The channel needs to be open.");
39-
}));
33+
glib::spawn_future_local(clone!(
34+
#[strong]
35+
sender,
36+
async move {
37+
// Deactivate the button until the operation is done
38+
sender
39+
.send(false)
40+
.await
41+
.expect("The channel needs to be open.");
42+
glib::timeout_future_seconds(5).await;
43+
// Activate the button again
44+
sender
45+
.send(true)
46+
.await
47+
.expect("The channel needs to be open.");
48+
}
49+
));
4050
});
4151

4252
// The main loop executes the asynchronous block
43-
glib::spawn_future_local(clone!(@weak button => async move {
44-
while let Ok(enable_button) = receiver.recv().await {
45-
button.set_sensitive(enable_button);
53+
glib::spawn_future_local(clone!(
54+
#[weak]
55+
button,
56+
async move {
57+
while let Ok(enable_button) = receiver.recv().await {
58+
button.set_sensitive(enable_button);
59+
}
4660
}
47-
}));
61+
));
4862
// ANCHOR_END: callback
4963

5064
// Create a window

book/listings/main_event_loop/5/main.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ fn build_ui(app: &Application) {
2828
// ANCHOR: callback
2929
// Connect to "clicked" signal of `button`
3030
button.connect_clicked(move |button| {
31-
glib::spawn_future_local(clone!(@weak button => async move {
32-
// Deactivate the button until the operation is done
33-
button.set_sensitive(false);
34-
glib::timeout_future_seconds(5).await;
35-
// Activate the button again
36-
button.set_sensitive(true);
37-
}));
31+
glib::spawn_future_local(clone!(
32+
#[weak]
33+
button,
34+
async move {
35+
// Deactivate the button until the operation is done
36+
button.set_sensitive(false);
37+
glib::timeout_future_seconds(5).await;
38+
// Activate the button again
39+
button.set_sensitive(true);
40+
}
41+
));
3842
});
3943
// ANCHOR_END: callback
4044

0 commit comments

Comments
 (0)