Skip to content

Commit 4e06a9a

Browse files
committed
clean: clippy --fix
1 parent cc42925 commit 4e06a9a

18 files changed

Lines changed: 103 additions & 111 deletions

File tree

src/app/apps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl App {
306306
.height(50);
307307

308308
container(content)
309-
.id(format!("result-{}", id_num))
309+
.id(format!("result-{id_num}"))
310310
.style(move |_| result_row_container_style(&theme, focused))
311311
.padding(8)
312312
.width(Fill)

src/app/menubar.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn init_event_handler(sender: ExtSender) {
9797
}
9898
"open_issue_page" => {
9999
if let Err(e) = open::that("https://github.com/unsecretised/rustcast/issues/new") {
100-
tracing::error!("Error opening url: {}", e)
100+
tracing::error!("Error opening url: {}", e);
101101
}
102102
}
103103
"show_rustcast" => {
@@ -112,15 +112,15 @@ fn init_event_handler(sender: ExtSender) {
112112
if let Err(e) = open::that(
113113
"https://github.com/unsecretised/rustcast/discussions/new?category=q-a",
114114
) {
115-
tracing::error!("Error opening url: {}", e)
115+
tracing::error!("Error opening url: {}", e);
116116
}
117117
}
118118
"open_preferences" => {
119119
open_settings();
120120
}
121121
"open_github_page" => {
122122
if let Err(e) = open::that("https://github.com/unsecretised/rustcast") {
123-
tracing::error!("Error opening url: {}", e)
123+
tracing::error!("Error opening url: {}", e);
124124
}
125125
}
126126
_ => {}

src/app/pages/clipboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn clipboard_view(
3131
clipboard_content
3232
.get(focussed_id as usize)
3333
.map(|x| x.to_app().alias)
34-
.unwrap_or("".to_string()),
34+
.unwrap_or_default(),
3535
)
3636
.height(385)
3737
.width(Length::Fill)

src/app/pages/emoji.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn emoji_page(
99
) -> Element<'static, Message> {
1010
let emoji_vec = emojis
1111
.chunks(6)
12-
.map(|x| x.to_vec())
12+
.map(<[crate::app::apps::App]>::to_vec)
1313
.collect::<Vec<Vec<App>>>();
1414

1515
let mut column = Vec::new();
@@ -43,7 +43,7 @@ pub fn emoji_page(
4343
)
4444
.width(70)
4545
.height(70)
46-
.id(format!("result-{}", id_num))
46+
.id(format!("result-{id_num}"))
4747
.style(move |_| emoji_button_container_style(&theme_clone, focussed_id == id_num)),
4848
container(
4949
Text::new(emoji.desc)

src/app/tile/elm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ pub fn new(
111111
let options = index_installed_apps(config);
112112

113113
if let Err(ref e) = options {
114-
tracing::error!("Error indexing apps: {e}")
114+
tracing::error!("Error indexing apps: {e}");
115115
}
116116

117117
// Still try to load the rest
118118
let mut options = options.unwrap_or_default();
119119

120-
options.extend(config.shells.iter().map(|x| x.to_app()));
120+
options.extend(config.shells.iter().map(crate::config::Shelly::to_app));
121121
options.extend(App::basic_apps());
122122
options.par_sort_by_key(|x| x.name.len());
123123
let options = AppIndex::from_apps(options);
@@ -133,7 +133,7 @@ pub fn new(
133133
visible: true,
134134
focused: false,
135135
config: config.clone(),
136-
theme: config.theme.to_owned().into(),
136+
theme: config.theme.clone().into(),
137137
clipboard_content: vec![],
138138
tray_icon: None,
139139
sender: None,
@@ -204,7 +204,7 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
204204
tile.config.theme.clone(),
205205
tile.emoji_apps
206206
.search_prefix(&tile.query_lc)
207-
.map(|x| x.to_owned())
207+
.map(std::borrow::ToOwned::to_owned)
208208
.collect(),
209209
tile.focus_id,
210210
)
@@ -274,7 +274,7 @@ fn footer(theme: Theme, results_count: usize) -> Element<'static, Message> {
274274
} else if results_count == 1 {
275275
"1 result found"
276276
} else {
277-
&format!("{} results found", results_count)
277+
&format!("{results_count} results found")
278278
};
279279

280280
container(

src/app/tile/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl Tile {
232232
};
233233
let results: Vec<App> = options
234234
.search_prefix(&query)
235-
.map(|x| x.to_owned())
235+
.map(std::borrow::ToOwned::to_owned)
236236
.collect();
237237

238238
self.results = results;
@@ -292,9 +292,9 @@ impl Tile {
292292
fn handle_hot_reloading() -> impl futures::Stream<Item = Message> {
293293
stream::channel(100, async |mut output| {
294294
let mut content = fs::read_to_string(
295-
std::env::var("HOME").unwrap_or("".to_owned()) + "/.config/rustcast/config.toml",
295+
std::env::var("HOME").unwrap_or_default() + "/.config/rustcast/config.toml",
296296
)
297-
.unwrap_or("".to_string());
297+
.unwrap_or_default();
298298

299299
let paths = default_app_paths();
300300
let mut total_files: usize = paths
@@ -304,9 +304,9 @@ fn handle_hot_reloading() -> impl futures::Stream<Item = Message> {
304304

305305
loop {
306306
let current_content = fs::read_to_string(
307-
std::env::var("HOME").unwrap_or("".to_owned()) + "/.config/rustcast/config.toml",
307+
std::env::var("HOME").unwrap_or_default() + "/.config/rustcast/config.toml",
308308
)
309-
.unwrap_or("".to_string());
309+
.unwrap_or_default();
310310

311311
let current_total_files: usize = paths
312312
.par_iter()
@@ -334,7 +334,7 @@ fn count_dirs_in_dir(dir: &PathBuf) -> usize {
334334
};
335335

336336
entries
337-
.filter_map(|entry| entry.ok())
337+
.filter_map(std::result::Result::ok)
338338
.filter(|entry| entry.file_type().map(|t| t.is_dir()).unwrap_or(false))
339339
.count()
340340
}

src/app/tile/search_query.rs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,45 +53,44 @@ pub(super) fn handle_change(tile: &mut Tile, input: &str, id: Id) -> iced::Task<
5353
height: 55. + DEFAULT_WINDOW_HEIGHT,
5454
},
5555
);
56-
} else {
57-
if tile.query_lc == "67" {
58-
tile.results = vec![App::new_builtin(
59-
"67",
60-
"",
61-
"Easter egg",
62-
AppCommand::Function(Function::RandomVar(67)),
63-
)];
64-
return window::resize(
65-
id,
66-
iced::Size {
67-
width: WINDOW_WIDTH,
68-
height: 55. + DEFAULT_WINDOW_HEIGHT,
69-
},
70-
);
71-
}
72-
if tile.query_lc.ends_with("?") {
73-
tile.results = vec![App::new_builtin(
74-
&format!("Search for: {}", tile.query),
75-
"",
76-
"Web Search",
77-
AppCommand::Function(Function::GoogleSearch(tile.query.clone())),
78-
)];
79-
return window::resize(
80-
id,
81-
iced::Size::new(WINDOW_WIDTH, 55. + DEFAULT_WINDOW_HEIGHT),
82-
);
83-
} else if tile.query_lc == "cbhist" {
84-
tile.page = Page::ClipboardHistory
85-
} else if tile.query_lc == "main" {
86-
tile.page = Page::Main
87-
}
56+
}
57+
if tile.query_lc == "67" {
58+
tile.results = vec![App::new_builtin(
59+
"67",
60+
"",
61+
"Easter egg",
62+
AppCommand::Function(Function::RandomVar(67)),
63+
)];
64+
return window::resize(
65+
id,
66+
iced::Size {
67+
width: WINDOW_WIDTH,
68+
height: 55. + DEFAULT_WINDOW_HEIGHT,
69+
},
70+
);
71+
}
72+
if tile.query_lc.ends_with('?') {
73+
tile.results = vec![App::new_builtin(
74+
&format!("Search for: {}", tile.query),
75+
"",
76+
"Web Search",
77+
AppCommand::Function(Function::GoogleSearch(tile.query.clone())),
78+
)];
79+
return window::resize(
80+
id,
81+
iced::Size::new(WINDOW_WIDTH, 55. + DEFAULT_WINDOW_HEIGHT),
82+
);
83+
} else if tile.query_lc == "cbhist" {
84+
tile.page = Page::ClipboardHistory;
85+
} else if tile.query_lc == "main" {
86+
tile.page = Page::Main;
8887
}
8988
tile.handle_search_query_changed();
9089

9190
if tile.results.is_empty()
9291
&& let Some(res) = Expr::from_str(&tile.query).ok()
9392
{
94-
let res_string = res.eval().map(|x| x.to_string()).unwrap_or(String::new());
93+
let res_string = res.eval().map_or(String::new(), |x| x.to_string());
9594
tile.results.push(App::new_builtin(
9695
RUSTCAST_DESC_NAME,
9796
&res_string,
@@ -155,7 +154,7 @@ pub(super) fn handle_change(tile: &mut Tile, input: &str, id: Id) -> iced::Task<
155154
tile.results = tile
156155
.emoji_apps
157156
.search_prefix("")
158-
.map(|x| x.to_owned())
157+
.map(std::borrow::ToOwned::to_owned)
159158
.collect();
160159
}
161160

src/app/tile/update.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
174174
Message::ReloadConfig => {
175175
let new_config: Config = match toml::from_str(
176176
&fs::read_to_string(
177-
std::env::var("HOME").unwrap_or("".to_owned())
177+
std::env::var("HOME").unwrap_or_default()
178178
+ "/.config/rustcast/config.toml",
179179
)
180-
.unwrap_or("".to_owned()),
180+
.unwrap_or_default(),
181181
) {
182182
Ok(a) => a,
183183
Err(_) => return Task::none(),
@@ -189,11 +189,11 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
189189
Err(e) => tracing::error!("Error indexing apps: {e}"),
190190
}
191191

192-
options.extend(new_config.shells.iter().map(|x| x.to_app()));
192+
options.extend(new_config.shells.iter().map(crate::config::Shelly::to_app));
193193
options.extend(App::basic_apps());
194194
options.par_sort_by_key(|x| x.name.len());
195195

196-
tile.theme = new_config.theme.to_owned().into();
196+
tile.theme = new_config.theme.clone().into();
197197
tile.config = new_config;
198198
tile.options = AppIndex::from_apps(options);
199199
Task::none()
@@ -227,8 +227,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
227227
// Linux Clipboard and Open Hotkey are gonna be handled via a socket
228228
let is_clipboard_hotkey = tile
229229
.clipboard_hotkey
230-
.map(|hotkey| hotkey.id == hk_id)
231-
.unwrap_or(false);
230+
.is_some_and(|hotkey| hotkey.id == hk_id);
232231

233232
let is_open_hotkey = hk_id == tile.hotkey.id;
234233

@@ -309,15 +308,13 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
309308

310309
Message::WindowFocusChanged(wid, focused) => {
311310
tile.focused = focused;
312-
if !focused {
313-
if cfg!(target_os = "macos") {
314-
Task::done(Message::HideWindow(wid))
315-
.chain(Task::done(Message::ClearSearchQuery))
316-
} else {
317-
// linux seems to not wanna unfocus it on start making it not show
318-
Task::none()
319-
}
311+
if focused {
312+
Task::none()
313+
} else if cfg!(target_os = "macos") {
314+
Task::done(Message::HideWindow(wid))
315+
.chain(Task::done(Message::ClearSearchQuery))
320316
} else {
317+
// linux seems to not wanna unfocus it on start making it not show
321318
Task::none()
322319
}
323320
}

src/calculator.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ pub enum BinOp {
4949

5050
impl Expr {
5151
pub fn eval(&self) -> Option<f64> {
52-
use BinOp::*;
53-
use UnaryOp::*;
52+
use BinOp::{Add, Sub, Mul, Div, Pow};
53+
use UnaryOp::{Plus, Minus};
5454
match self {
5555
Expr::Number(x) => Some(*x),
5656

@@ -196,9 +196,8 @@ impl<'a> Lexer<'a> {
196196
return self.lex_number();
197197
} else if c.is_ascii_alphabetic() || c == '_' {
198198
return self.lex_ident();
199-
} else {
200-
return Err(format!("Unexpected character: {c}"));
201199
}
200+
return Err(format!("Unexpected character: {c}"));
202201
}
203202
};
204203
Ok(tok)

src/clipboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl ClipBoardContentType {
3232
&name,
3333
&name_lc,
3434
"Clipboard Item",
35-
AppCommand::Function(Function::CopyToClipboard(self_clone.to_owned())),
35+
AppCommand::Function(Function::CopyToClipboard(self_clone.clone())),
3636
)
3737
}
3838
}

0 commit comments

Comments
 (0)