Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit e0e24b0

Browse files
examples: fix clippy warnings
1 parent 3ddea93 commit e0e24b0

7 files changed

+23
-18
lines changed

examples/src/bin/basic_subclass.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ glib_wrapper! {
199199
}
200200

201201
impl SimpleApplication {
202+
#[allow(clippy::new_without_default)]
202203
pub fn new() -> Self {
203204
glib::Object::new(
204205
Self::static_type(),

examples/src/bin/clipboard_simple.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ fn build_ui(application: &gtk::Application) {
7272
// Save out UI in thread-local storage so we can use it in callbacks later
7373
GLOBAL.with(move |global| {
7474
*global.borrow_mut() = Some(Ui {
75-
button_a1: button_a1,
76-
button_a2: button_a2,
77-
button_b1: button_b1,
78-
button_b2: button_b2,
75+
button_a1,
76+
button_a2,
77+
button_b1,
78+
button_b2,
7979
})
8080
});
8181

@@ -112,12 +112,11 @@ fn build_ui(application: &gtk::Application) {
112112
paste_button.connect_clicked(|_| {
113113
let clipboard = gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD);
114114
clipboard.request_text(|_, t| {
115-
if t.is_some() {
116-
let t = t.unwrap();
115+
if let Some(t) = t {
117116
if t.len() >= 4 {
118117
GLOBAL.with(|global| {
119118
if let Some(ref ui) = *global.borrow() {
120-
ui.button_a1.set_active(t.chars().nth(0).unwrap() == '1');
119+
ui.button_a1.set_active(t.starts_with('1'));
121120
ui.button_a2.set_active(t.chars().nth(1).unwrap() == '1');
122121
ui.button_b1.set_active(t.chars().nth(2).unwrap() == '1');
123122
ui.button_b2.set_active(t.chars().nth(3).unwrap() == '1');

examples/src/bin/gio_futures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn read_and_print_file(
1919
) -> impl Future<Output = Result<(), String>> + std::marker::Unpin {
2020
file.read_async_future(glib::PRIORITY_DEFAULT)
2121
.map_err(|err| format!("Failed to open file: {}", err))
22-
.and_then(|strm| read_and_print_chunks(strm))
22+
.and_then(read_and_print_chunks)
2323
}
2424

2525
// Read the input stream in chunks of 64 bytes, always into the same buffer

examples/src/bin/iconview_example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn create_list_store_model() -> gtk::ListStore {
7070
}
7171
}
7272

73-
return icon_view_model;
73+
icon_view_model
7474
}
7575

7676
fn build_ui(application: &gtk::Application) {

examples/src/bin/list_store.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ extern crate glib;
33
extern crate gtk;
44

55
use gio::prelude::*;
6+
use glib::clone;
67
use gtk::prelude::*;
78

89
use std::env::args;
@@ -55,8 +56,13 @@ fn build_ui(application: &gtk::Application) {
5556

5657
window.show_all();
5758

58-
let model = model.clone();
59-
glib::timeout_add_local(Duration::from_millis(80), move || spinner_timeout(&model));
59+
glib::timeout_add_local(
60+
Duration::from_millis(80),
61+
clone!(@weak model => @default-return glib::Continue(false), move || {
62+
spinner_timeout(&model);
63+
glib::Continue(false)
64+
}),
65+
);
6066
}
6167

6268
struct Data {

examples/src/bin/progress_tracker.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ impl Application {
7575
let _ = tx.send(None);
7676
});
7777

78-
let active = active.clone();
79-
let widgets = widgets.clone();
80-
rx.attach(None, move |value| match value {
78+
rx.attach(None, clone!(@weak active, @weak widgets => @default-return glib::Continue(false), move |value| match value {
8179
Some(value) => {
8280
widgets
8381
.main_view
@@ -105,7 +103,7 @@ impl Application {
105103
active.set(false);
106104
glib::Continue(false)
107105
}
108-
});
106+
}));
109107
}),
110108
);
111109
}
@@ -160,6 +158,7 @@ pub struct Header {
160158
}
161159

162160
impl Header {
161+
#[allow(clippy::new_without_default)]
163162
pub fn new() -> Self {
164163
let container = gtk::HeaderBar::new();
165164
container.set_title(Some("Progress Tracker"));
@@ -174,6 +173,7 @@ pub struct CompleteView {
174173
}
175174

176175
impl CompleteView {
176+
#[allow(clippy::new_without_default)]
177177
pub fn new() -> Self {
178178
let label = gtk::Label::new(None);
179179
label.set_markup("Task complete");
@@ -198,6 +198,7 @@ pub struct MainView {
198198
}
199199

200200
impl MainView {
201+
#[allow(clippy::new_without_default)]
201202
pub fn new() -> Self {
202203
let progress = gtk::ProgressBar::new();
203204
progress.set_text(Some("Progress Bar"));

examples/src/bin/treeview.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn build_ui(application: &gtk::Application) {
6868
col.pack_start(&renderer2, true);
6969
col.add_attribute(&renderer2, "text", 1);
7070
let image = Pixbuf::from_file("./resources/eye.png")
71-
.or_else(|err| {
71+
.map_err(|err| {
7272
let mut msg = err.to_string();
7373
if err.kind() == Some(glib::FileError::Noent) {
7474
msg.push_str(
@@ -86,8 +86,6 @@ fn build_ui(application: &gtk::Application) {
8686
Continue(false)
8787
}),
8888
);
89-
90-
Err(())
9189
})
9290
.ok();
9391

0 commit comments

Comments
 (0)