Skip to content

Commit 8e0f1c4

Browse files
authored
chore: apply recommendations from clippy
1 parent cec55da commit 8e0f1c4

File tree

56 files changed

+726
-830
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+726
-830
lines changed

cosmic-app-list/cosmic-app-list-config/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl AppListConfig {
4242
}
4343

4444
pub fn remove_pinned(&mut self, id: &str, config: &Config) {
45-
if let Some(pos) = self.favorites.iter().position(|e| e == &id) {
45+
if let Some(pos) = self.favorites.iter().position(|e| e == id) {
4646
self.favorites.remove(pos);
4747
let _ = self.write_entry(config);
4848
}

cosmic-app-list/src/app.rs

Lines changed: 141 additions & 150 deletions
Large diffs are not rendered by default.

cosmic-app-list/src/localize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ pub fn localize() {
4343
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
4444

4545
if let Err(error) = localizer.select(&requested_languages) {
46-
eprintln!("Error while loading language for App List {}", error);
46+
eprintln!("Error while loading language for App List {error}");
4747
}
4848
}

cosmic-app-list/src/wayland_handler.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl ActivationHandler for AppData {
179179
fn new_token(&mut self, token: String, data: &ExecRequestData) {
180180
let _ = self.tx.unbounded_send(WaylandUpdate::ActivationToken {
181181
token: Some(token),
182-
app_id: data.app_id().map(|x| x.to_owned()),
182+
app_id: data.app_id().map(String::from),
183183
exec: data.exec.clone(),
184184
gpu_idx: data.gpu_idx,
185185
terminal: data.terminal,
@@ -313,7 +313,10 @@ impl Session {
313313
self.condvar.notify_all();
314314
}
315315

316-
fn wait_while<F: FnMut(&SessionInner) -> bool>(&self, mut f: F) -> MutexGuard<SessionInner> {
316+
fn wait_while<F: FnMut(&SessionInner) -> bool>(
317+
&self,
318+
mut f: F,
319+
) -> MutexGuard<'_, SessionInner> {
317320
self.condvar
318321
.wait_while(self.inner.lock().unwrap(), |data| f(data))
319322
.unwrap()
@@ -337,7 +340,7 @@ impl Dispatch<wl_shm_pool::WlShmPool, ()> for AppData {
337340
_app_data: &mut Self,
338341
_buffer: &wl_shm_pool::WlShmPool,
339342
_event: wl_shm_pool::Event,
340-
_: &(),
343+
(): &(),
341344
_: &Connection,
342345
_qh: &QueueHandle<Self>,
343346
) {
@@ -349,7 +352,7 @@ impl Dispatch<wl_buffer::WlBuffer, ()> for AppData {
349352
_app_data: &mut Self,
350353
_buffer: &wl_buffer::WlBuffer,
351354
_event: wl_buffer::Event,
352-
_: &(),
355+
(): &(),
353356
_: &Connection,
354357
_qh: &QueueHandle<Self>,
355358
) {
@@ -387,7 +390,7 @@ impl CaptureData {
387390
&self.qh,
388391
SessionData {
389392
session: session.clone(),
390-
session_data: Default::default(),
393+
session_data: ScreencopySessionData::default(),
391394
},
392395
)
393396
.unwrap();
@@ -405,22 +408,19 @@ impl CaptureData {
405408
}
406409

407410
// XXX
408-
if !formats
409-
.shm_formats
410-
.contains(&wl_shm::Format::Abgr8888.into())
411-
{
411+
if !formats.shm_formats.contains(&wl_shm::Format::Abgr8888) {
412412
tracing::error!("No suitable buffer format found");
413413
tracing::warn!("Available formats: {:#?}", formats);
414414
return None;
415-
};
415+
}
416416

417417
let buf_len = width * height * 4;
418418
if let Some(len) = len {
419419
if len != buf_len {
420420
return None;
421421
}
422-
} else if let Err(_err) = rustix::fs::ftruncate(&fd, buf_len as _) {
423-
};
422+
} else if let Err(_err) = rustix::fs::ftruncate(&fd, buf_len.into()) {
423+
}
424424
let pool = self
425425
.wl_shm
426426
.create_pool(fd.as_fd(), buf_len as i32, &self.qh, ());
@@ -439,7 +439,7 @@ impl CaptureData {
439439
&[],
440440
&self.qh,
441441
FrameData {
442-
frame_data: Default::default(),
442+
frame_data: ScreencopyFrameData::default(),
443443
session: capture_session.clone(),
444444
},
445445
);
@@ -484,7 +484,7 @@ impl AppData {
484484
handle: &ExtForeignToplevelHandleV1,
485485
) -> Option<ZcosmicToplevelHandleV1> {
486486
self.toplevel_info_state
487-
.info(&handle)?
487+
.info(handle)?
488488
.cosmic_toplevel
489489
.clone()
490490
}
@@ -498,8 +498,7 @@ impl AppData {
498498
capturer: self.screencopy_state.capturer().clone(),
499499
};
500500
std::thread::spawn(move || {
501-
use std::ffi::CStr;
502-
let name = unsafe { CStr::from_bytes_with_nul_unchecked(b"app-list-screencopy\0") };
501+
let name = c"app-list-screencopy";
503502
let Ok(fd) = rustix::fs::memfd_create(name, rustix::fs::MemfdFlags::CLOEXEC) else {
504503
tracing::error!("Failed to get fd for capture");
505504
return;
@@ -535,7 +534,7 @@ impl AppData {
535534
tx.unbounded_send(WaylandUpdate::Image(handle, WaylandImage::new(img)))
536535
{
537536
tracing::error!("Failed to send image event to subscription {err:?}");
538-
};
537+
}
539538
} else {
540539
tracing::error!("Failed to capture image");
541540
}
@@ -624,7 +623,7 @@ pub(crate) fn wayland_handler(
624623
.expect("Failed to insert wayland source.");
625624

626625
if handle
627-
.insert_source(rx, |event, _, state| match event {
626+
.insert_source(rx, |event, (), state| match event {
628627
calloop::channel::Event::Msg(req) => match req {
629628
WaylandRequest::Screencopy(handle) => {
630629
state.send_image(handle.clone());

cosmic-app-list/src/wayland_subscription.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,13 @@ async fn start_listening(
9191
}
9292
guard.as_mut().unwrap()
9393
};
94-
match rx.next().await {
95-
Some(u) => {
96-
_ = output.send(u).await;
97-
State::Waiting
98-
}
99-
None => {
100-
_ = output.send(WaylandUpdate::Finished).await;
101-
tracing::error!("Wayland handler thread died");
102-
State::Finished
103-
}
94+
if let Some(u) = rx.next().await {
95+
_ = output.send(u).await;
96+
State::Waiting
97+
} else {
98+
_ = output.send(WaylandUpdate::Finished).await;
99+
tracing::error!("Wayland handler thread died");
100+
State::Finished
104101
}
105102
}
106103
State::Finished => iced::futures::future::pending().await,

cosmic-applet-a11y/src/app.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl cosmic::Application for CosmicA11yApplet {
235235
});
236236
} else {
237237
tracing::error!("Wayland tx is None");
238-
};
238+
}
239239
}
240240
Message::Token(u) => match u {
241241
TokenUpdate::Init(tx) => {
@@ -303,15 +303,15 @@ impl cosmic::Application for CosmicA11yApplet {
303303
Task::none()
304304
}
305305

306-
fn view(&self) -> Element<Message> {
306+
fn view(&self) -> Element<'_, Message> {
307307
self.core
308308
.applet
309309
.icon_button("preferences-desktop-accessibility-symbolic")
310310
.on_press_down(Message::TogglePopup)
311311
.into()
312312
}
313313

314-
fn view_window(&self, _id: window::Id) -> Element<Message> {
314+
fn view_window(&self, _id: window::Id) -> Element<'_, Message> {
315315
let Spacing {
316316
space_xxs, space_s, ..
317317
} = theme::active().cosmic().spacing;

cosmic-applet-a11y/src/backend/wayland/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ pub struct WaylandWatcher {
8282
impl WaylandWatcher {
8383
pub fn new() -> anyhow::Result<Self> {
8484
let (tx, rx) = thread::spawn_wayland_connection(1)?;
85-
Ok(Self { tx, rx })
85+
Ok(Self { rx, tx })
8686
}
8787
}

cosmic-applet-a11y/src/localize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ pub fn localize() {
4343
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
4444

4545
if let Err(error) = localizer.select(&requested_languages) {
46-
eprintln!("Error while loading language for App List {}", error);
46+
eprintln!("Error while loading language for App List {error}");
4747
}
4848
}

cosmic-applet-audio/src/lib.rs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,21 @@ pub enum Message {
166166
}
167167

168168
impl Audio {
169-
fn playback_buttons(&self) -> Option<Element<Message>> {
169+
fn playback_buttons(&self) -> Option<Element<'_, Message>> {
170170
if self.player_status.is_some() && self.config.show_media_controls_in_top_panel {
171171
let mut elements = Vec::with_capacity(3);
172172
if self
173173
.player_status
174174
.as_ref()
175-
.map(|s| s.can_go_previous)
176-
.unwrap_or_default()
175+
.is_some_and(|s| s.can_go_previous)
177176
{
178177
elements.push(
179178
self.core
180179
.applet
181180
.icon_button(GO_BACK)
182181
.on_press(Message::MprisRequest(MprisRequest::Previous))
183182
.into(),
184-
)
183+
);
185184
}
186185
if let Some(play) = self.is_play() {
187186
elements.push(
@@ -196,12 +195,7 @@ impl Audio {
196195
.into(),
197196
);
198197
}
199-
if self
200-
.player_status
201-
.as_ref()
202-
.map(|s| s.can_go_next)
203-
.unwrap_or_default()
204-
{
198+
if self.player_status.as_ref().is_some_and(|s| s.can_go_next) {
205199
elements.push(
206200
self.core
207201
.applet
@@ -224,7 +218,7 @@ impl Audio {
224218
}
225219
}
226220

227-
fn go_previous(&self, icon_size: u16) -> Option<Element<Message>> {
221+
fn go_previous(&self, icon_size: u16) -> Option<Element<'_, Message>> {
228222
self.player_status.as_ref().and_then(|s| {
229223
if s.can_go_previous {
230224
Some(
@@ -240,7 +234,7 @@ impl Audio {
240234
})
241235
}
242236

243-
fn go_next(&self, icon_size: u16) -> Option<Element<Message>> {
237+
fn go_next(&self, icon_size: u16) -> Option<Element<'_, Message>> {
244238
self.player_status.as_ref().and_then(|s| {
245239
if s.can_go_next {
246240
Some(
@@ -277,17 +271,11 @@ impl Audio {
277271
}
278272

279273
fn current_output_mute(&self) -> bool {
280-
self.current_output
281-
.as_ref()
282-
.map(|o| o.mute)
283-
.unwrap_or_default()
274+
self.current_output.as_ref().is_some_and(|o| o.mute)
284275
}
285276

286277
fn current_input_mute(&self) -> bool {
287-
self.current_input
288-
.as_ref()
289-
.map(|o| o.mute)
290-
.unwrap_or_default()
278+
self.current_input.as_ref().is_some_and(|o| o.mute)
291279
}
292280
}
293281

@@ -421,7 +409,7 @@ impl cosmic::Application for Audio {
421409
connection.send(pulse::Message::SetSourceVolumeByName(
422410
name.clone(),
423411
device.volume,
424-
))
412+
));
425413
}
426414
}
427415
}
@@ -434,7 +422,7 @@ impl cosmic::Application for Audio {
434422
if let Some(device) = &self.current_output {
435423
if let Some(name) = &device.name {
436424
connection
437-
.send(pulse::Message::SetSinkMuteByName(name.clone(), device.mute))
425+
.send(pulse::Message::SetSinkMuteByName(name.clone(), device.mute));
438426
}
439427
}
440428
}
@@ -625,7 +613,7 @@ impl cosmic::Application for Audio {
625613
});
626614
} else {
627615
tracing::error!("Wayland tx is None");
628-
};
616+
}
629617
}
630618
Message::Token(u) => match u {
631619
TokenUpdate::Init(tx) => {
@@ -688,7 +676,7 @@ impl cosmic::Application for Audio {
688676
cosmic::app::Action::Surface(a),
689677
));
690678
}
691-
};
679+
}
692680

693681
Task::none()
694682
}
@@ -711,7 +699,7 @@ impl cosmic::Application for Audio {
711699
])
712700
}
713701

714-
fn view(&self) -> Element<Message> {
702+
fn view(&self) -> Element<'_, Message> {
715703
let btn = self
716704
.core
717705
.applet
@@ -765,7 +753,7 @@ impl cosmic::Application for Audio {
765753
.into()
766754
}
767755

768-
fn view_window(&self, _id: window::Id) -> Element<Message> {
756+
fn view_window(&self, _id: window::Id) -> Element<'_, Message> {
769757
let Spacing {
770758
space_xxs, space_s, ..
771759
} = theme::active().cosmic().spacing;

cosmic-applet-audio/src/localize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ pub fn localize() {
4343
let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages();
4444

4545
if let Err(error) = localizer.select(&requested_languages) {
46-
eprintln!("Error while loading language for App List {}", error);
46+
eprintln!("Error while loading language for App List {error}");
4747
}
4848
}

0 commit comments

Comments
 (0)