Skip to content

Commit 7c07bbe

Browse files
authored
Merge pull request #708 from JakeStanger/refactor/clippy
refactor: fix some pedantic clippy warnings
2 parents 4d30819 + 04f45cc commit 7c07bbe

File tree

12 files changed

+43
-46
lines changed

12 files changed

+43
-46
lines changed

src/bar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl Bar {
346346

347347
/// Sets the window visibility status
348348
pub fn set_visible(&self, visible: bool) {
349-
self.window.set_visible(visible)
349+
self.window.set_visible(visible);
350350
}
351351

352352
pub fn set_exclusive(&self, exclusive: bool) {

src/clients/music/mpris.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl Client {
5454
vec![]
5555
}
5656
});
57+
5758
// Acquire the lock of current_player before players to avoid deadlock.
5859
// There are places where we lock on current_player and players, but we always lock on current_player first.
5960
// This is because we almost never need to lock on players without locking on current_player.

src/clients/sway.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl Client {
5656
T::EVENT_TYPE,
5757
Box::new(move |event| {
5858
let event = T::from_event(event).expect("event type mismatch");
59-
f(event)
59+
f(event);
6060
}),
6161
)
6262
.await

src/clients/wayland/wlr_foreign_toplevel/handle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ where
146146
ToplevelHandle {
147147
handle: handle.clone(),
148148
},
149-
)
149+
);
150150
}
151151
Event::Done if !lock!(data.inner).closed => {
152152
{

src/config/impl.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,18 @@ impl<'de> Deserialize<'de> for MonitorConfig {
3737

3838
pub fn deserialize_layer<'de, D>(deserializer: D) -> Result<gtk_layer_shell::Layer, D::Error>
3939
where
40-
D: serde::Deserializer<'de>,
40+
D: Deserializer<'de>,
4141
{
4242
use gtk_layer_shell::Layer;
4343

4444
let value = Option::<String>::deserialize(deserializer)?;
45-
value
46-
.map(|v| match v.as_str() {
47-
"background" => Ok(Layer::Background),
48-
"bottom" => Ok(Layer::Bottom),
49-
"top" => Ok(Layer::Top),
50-
"overlay" => Ok(Layer::Overlay),
51-
_ => Err(serde::de::Error::custom("invalid value for orientation")),
52-
})
53-
.unwrap_or(Ok(Layer::Top))
45+
value.map_or(Ok(Layer::Top), |v| match v.as_str() {
46+
"background" => Ok(Layer::Background),
47+
"bottom" => Ok(Layer::Bottom),
48+
"top" => Ok(Layer::Top),
49+
"overlay" => Ok(Layer::Overlay),
50+
_ => Err(serde::de::Error::custom("invalid value for orientation")),
51+
})
5452
}
5553

5654
#[cfg(feature = "schema")]

src/ipc/server/bar.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ use crate::Ironbar;
66
use std::rc::Rc;
77

88
pub fn handle_command(command: BarCommand, ironbar: &Rc<Ironbar>) -> Response {
9+
use BarCommandType::*;
10+
911
let bar = ironbar.bar_by_name(&command.name);
1012
let Some(bar) = bar else {
1113
return Response::error("Invalid bar name");
1214
};
1315

14-
use BarCommandType::*;
1516
match command.subcommand {
1617
Show => set_visible(&bar, true),
1718
Hide => set_visible(&bar, false),
@@ -21,14 +22,14 @@ pub fn handle_command(command: BarCommand, ironbar: &Rc<Ironbar>) -> Response {
2122
value: bar.visible().to_string(),
2223
},
2324

24-
ShowPopup { widget_name } => show_popup(&bar, widget_name),
25+
ShowPopup { widget_name } => show_popup(&bar, &widget_name),
2526
HidePopup => hide_popup(&bar),
2627
SetPopupVisible {
2728
widget_name,
2829
visible,
2930
} => {
3031
if visible {
31-
show_popup(&bar, widget_name)
32+
show_popup(&bar, &widget_name)
3233
} else {
3334
hide_popup(&bar)
3435
}
@@ -37,7 +38,7 @@ pub fn handle_command(command: BarCommand, ironbar: &Rc<Ironbar>) -> Response {
3738
if bar.popup().visible() {
3839
hide_popup(&bar)
3940
} else {
40-
show_popup(&bar, widget_name)
41+
show_popup(&bar, &widget_name)
4142
}
4243
}
4344
GetPopupVisible => Response::OkValue {
@@ -56,7 +57,7 @@ fn set_visible(bar: &Bar, visible: bool) -> Response {
5657
Response::Ok
5758
}
5859

59-
fn show_popup(bar: &Bar, widget_name: String) -> Response {
60+
fn show_popup(bar: &Bar, widget_name: &str) -> Response {
6061
let popup = bar.popup();
6162

6263
// only one popup per bar, so hide if open for another widget

src/main.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn run_with_args() {
8888
match args.command {
8989
Some(command) => {
9090
if args.debug {
91-
eprintln!("REQUEST: {command:?}")
91+
eprintln!("REQUEST: {command:?}");
9292
}
9393

9494
let rt = create_runtime();
@@ -97,10 +97,10 @@ fn run_with_args() {
9797
match ipc.send(command, args.debug).await {
9898
Ok(res) => {
9999
if args.debug {
100-
eprintln!("RESPONSE: {res:?}")
100+
eprintln!("RESPONSE: {res:?}");
101101
}
102102

103-
cli::handle_response(res, args.format.unwrap_or_default())
103+
cli::handle_response(res, args.format.unwrap_or_default());
104104
}
105105
Err(err) => error!("{err:?}"),
106106
};
@@ -374,12 +374,11 @@ fn load_output_bars(
374374
let map = INDEX_MAP.get_or_init(|| Mutex::new(vec![]));
375375

376376
let index = lock!(map).iter().position(|n| n == monitor_name);
377-
let index = match index {
378-
Some(index) => index,
379-
None => {
380-
lock!(map).push(monitor_name.clone());
381-
lock!(map).len() - 1
382-
}
377+
let index = if let Some(index) = index {
378+
index
379+
} else {
380+
lock!(map).push(monitor_name.clone());
381+
lock!(map).len() - 1
383382
};
384383

385384
let config = ironbar.config.borrow();

src/modules/cairo.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Module<gtk::Box> for CairoModule {
7474
where
7575
<Self as Module<gtk::Box>>::SendMessage: Clone,
7676
{
77-
let path = self.path.to_path_buf();
77+
let path = self.path.clone();
7878

7979
let tx = context.tx.clone();
8080
spawn(async move {
@@ -160,16 +160,14 @@ impl Module<gtk::Box> for CairoModule {
160160
let ptr = unsafe { cr.clone().into_glib_ptr().cast() };
161161

162162
// mlua needs a valid return type, even if we don't return anything
163-
164163
if let Err(err) =
165164
function.call::<_, Option<bool>>((id.as_str(), LightUserData(ptr)))
166165
{
167-
match err {
168-
Error::RuntimeError(message) => {
169-
let message = message.split_once("]:").expect("to exist").1;
170-
error!("[lua runtime error] {}:{message}", path.display())
171-
}
172-
_ => error!("{err}"),
166+
if let Error::RuntimeError(message) = err {
167+
let message = message.split_once("]:").expect("to exist").1;
168+
error!("[lua runtime error] {}:{message}", path.display());
169+
} else {
170+
error!("{err}");
173171
}
174172

175173
return Propagation::Stop;
@@ -196,10 +194,10 @@ impl Module<gtk::Box> for CairoModule {
196194
match res {
197195
Ok(script) => {
198196
match lua.load(&script).exec() {
199-
Ok(_) => {},
197+
Ok(()) => {},
200198
Err(Error::SyntaxError { message, ..}) => {
201199
let message = message.split_once("]:").expect("to exist").1;
202-
error!("[lua syntax error] {}:{message}", self.path.display())
200+
error!("[lua syntax error] {}:{message}", self.path.display());
203201
},
204202
Err(err) => error!("lua error: {err:?}")
205203
}

src/modules/sway/mode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ impl Module<Label> for SwayModeModule {
7070
let on_mode = move |mode: ModeEvent| {
7171
trace!("mode: {:?}", mode);
7272
label.set_use_markup(mode.pango_markup);
73-
if mode.change != "default" {
74-
label.set_markup(&mode.change)
75-
} else {
73+
if mode.change == "default" {
7674
label.set_markup("");
75+
} else {
76+
label.set_markup(&mode.change);
7777
}
7878
};
7979

src/modules/sysinfo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ pub struct SysInfoModule {
3333

3434
/// The orientation of text for the labels.
3535
///
36-
/// **Valid options**: `horizontal`, `vertical, `h`, `v`
36+
/// **Valid options**: `horizontal`, `vertical`, `h`, `v`
3737
/// <br>
3838
/// **Default** : `horizontal`
3939
#[serde(default)]
4040
orientation: ModuleOrientation,
4141

4242
/// The orientation by which the labels are laid out.
4343
///
44-
/// **Valid options**: `horizontal`, `vertical, `h`, `v`
44+
/// **Valid options**: `horizontal`, `vertical`, `h`, `v`
4545
/// <br>
4646
/// **Default** : `horizontal`
4747
direction: Option<ModuleOrientation>,

src/modules/tray/icon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn get_image_from_pixmap(item: &TrayMenu, size: u32) -> Result<Image> {
9494
return Err(Report::msg("empty pixmap"));
9595
}
9696

97-
let mut pixels = pixmap.pixels.to_vec();
97+
let mut pixels = pixmap.pixels.clone();
9898

9999
for i in (0..pixels.len()).step_by(4) {
100100
let alpha = pixels[i];

src/popup.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl Popup {
169169
button_id,
170170
orientation,
171171
&window,
172-
output_size.clone(),
172+
&output_size,
173173
);
174174
}
175175
}
@@ -202,7 +202,7 @@ impl Popup {
202202
button_id,
203203
self.pos.orientation(),
204204
&self.window,
205-
self.output_size.clone(),
205+
&self.output_size,
206206
);
207207
}
208208
}
@@ -230,7 +230,7 @@ impl Popup {
230230
button_id: usize,
231231
orientation: Orientation,
232232
window: &ApplicationWindow,
233-
output_size: Rc<RefCell<(i32, i32)>>,
233+
output_size: &Rc<RefCell<(i32, i32)>>,
234234
) {
235235
let button = buttons
236236
.iter()

0 commit comments

Comments
 (0)