Skip to content

Commit bb93867

Browse files
authored
Merge pull request #1018 from MaxVerevkin/fix_clippy
refactoring: fix all clippy warnings
2 parents b07d7af + 3540ae0 commit bb93867

File tree

10 files changed

+34
-62
lines changed

10 files changed

+34
-62
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ i3status-rust.iml
99

1010
*.bk
1111
/.config/
12+
13+
.cargo

src/blocks/github.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<'a> Notifications<'a> {
193193
return Ok(Some(notif));
194194
}
195195

196-
if self.next_page_url == "" {
196+
if self.next_page_url.is_empty() {
197197
return Ok(None);
198198
}
199199

src/blocks/hueshift.rs

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -81,36 +81,35 @@ impl HueshiftConfig {
8181

8282
/// Default current temp for any screens
8383
fn default_current_temp() -> u16 {
84-
6500 as u16
84+
6500
8585
}
8686
/// Max/Min hue temperature (min 1000K, max 10_000K)
8787
// TODO: Try to detect if we're using redshift or not
8888
// to set default max_temp either to 10_000K to 25_000K
8989
fn default_min_temp() -> u16 {
90-
1000 as u16
90+
1000
9191
}
9292
fn default_max_temp() -> u16 {
93-
10_000 as u16
93+
10_000
9494
}
9595

9696
fn default_step() -> u16 {
97-
100 as u16
97+
100
9898
}
9999

100100
/// Prefer any installed shifter, redshift is preferred though.
101101
fn default_hue_shifter() -> Option<HueShifter> {
102-
let (redshift, sct) = what_is_supported();
103-
if redshift {
104-
return Some(HueShifter::Redshift);
105-
} else if sct {
106-
return Some(HueShifter::Sct);
102+
if has_command("hueshift", "redshift").unwrap_or(false) {
103+
Some(HueShifter::Redshift)
104+
} else if has_command("hueshift", "sct").unwrap_or(false) {
105+
Some(HueShifter::Sct)
106+
} else {
107+
None
107108
}
108-
109-
None
110109
}
111110

112111
fn default_click_temp() -> u16 {
113-
6500 as u16
112+
6500
114113
}
115114

116115
fn default_color_overrides() -> Option<BTreeMap<String, String>> {
@@ -216,22 +215,6 @@ impl Block for Hueshift {
216215
}
217216
}
218217

219-
/// Currently, detects whether sct and redshift are installed.
220-
#[inline]
221-
fn what_is_supported() -> (bool, bool) {
222-
let has_redshift = match has_command("hueshift", "redshift") {
223-
Ok(has_redshift) => has_redshift,
224-
Err(_) => false,
225-
};
226-
227-
let has_sct = match has_command("hueshift", "sct") {
228-
Ok(has_sct) => has_sct,
229-
Err(_) => false,
230-
};
231-
232-
(has_redshift, has_sct)
233-
}
234-
235218
#[inline]
236219
fn update_hue(hue_shifter: &Option<HueShifter>, new_temp: u16) {
237220
match hue_shifter {

src/blocks/maildir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ impl MaildirConfig {
7676
Duration::from_secs(5)
7777
}
7878
fn default_threshold_warning() -> usize {
79-
1 as usize
79+
1
8080
}
8181
fn default_threshold_critical() -> usize {
82-
10 as usize
82+
10
8383
}
8484
fn default_icon() -> bool {
8585
true

src/blocks/music.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ impl Music {
117117

118118
// Calculate how many chars to keep from title and artist
119119
let mut ttrc = tlen - tnum;
120-
if ttrc < 1 || ttrc > 5000 {
120+
if !(1..5001).contains(&ttrc) {
121121
ttrc = 1
122122
}
123123

124124
let mut atrc = alen - anum;
125-
if atrc < 1 || atrc > 5000 {
125+
if !(1..5001).contains(&atrc) {
126126
atrc = 1
127127
}
128128

@@ -666,7 +666,7 @@ impl Block for Music {
666666

667667
match event.button {
668668
MouseButton::Left => {
669-
if action != "" && players.len() > 0 {
669+
if !action.is_empty() && players.len() > 0 {
670670
let metadata = players.first().unwrap();
671671
let m = Message::new_method_call(
672672
metadata.interface_name.clone(),

src/blocks/speedtest.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,13 @@ impl Block for SpeedTest {
221221
if self.config.bytes { "B/s" } else { "b/s" },
222222
));
223223

224-
// TODO: remove clippy workaround
225-
#[allow(clippy::unknown_clippy_lints)]
226-
#[allow(clippy::match_on_vec_items)]
227-
self.text[0].set_state(match_range!(vals[0], default: (State::Critical) {
228-
0.0 ; 25.0 => State::Good,
229-
25.0 ; 60.0 => State::Info,
230-
60.0 ; 100.0 => State::Warning
231-
}));
224+
// ping is in milliseconds
225+
self.text[0].set_state(match ping as i32 {
226+
0..=25_000 => State::Good,
227+
25_001..=60_000 => State::Info,
228+
60_001..=100_000 => State::Warning,
229+
_ => State::Critical,
230+
});
232231
}
233232

234233
Ok(None)

src/blocks/weather.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn find_ip_location() -> Result<Option<String>> {
7979
let city = http_call_result
8080
.content
8181
.pointer("/city")
82-
.map(|v| v.to_owned().to_string());
82+
.map(|v| v.to_string());
8383

8484
Ok(city)
8585
}
@@ -114,13 +114,12 @@ fn australian_apparent_temp(
114114

115115
let metric_apparent_temp =
116116
temp_celsius + 0.33 * water_vapor_pressure - 0.7 * metric_wind_speed - 4.0;
117-
let apparent_temp = if metric {
117+
118+
if metric {
118119
metric_apparent_temp
119120
} else {
120121
1.8 * metric_apparent_temp + 32.0
121-
};
122-
123-
apparent_temp
122+
}
124123
}
125124

126125
// Convert wind direction in azimuth degrees to abbreviation names
@@ -208,7 +207,7 @@ impl Weather {
208207
if (output.code >= 300 && output.code < 400) || output.code >= 500 {
209208
return Err(BlockError(
210209
"weather".to_owned(),
211-
format!("Invalid result from curl: {}", output.code).to_owned(),
210+
format!("Invalid result from curl: {}", output.code),
212211
));
213212
};
214213

@@ -332,7 +331,7 @@ impl ConfigBlock for Weather {
332331
let id = pseudo_uuid();
333332
Ok(Weather {
334333
id: id.clone(),
335-
weather: ButtonWidget::new(config.clone(), &id),
334+
weather: ButtonWidget::new(config, &id),
336335
format: block_config.format,
337336
weather_keys: HashMap::new(),
338337
service: block_config.service,

src/blocks/xrandr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl XrandrConfig {
102102
}
103103

104104
fn default_step_width() -> u32 {
105-
5 as u32
105+
5
106106
}
107107

108108
fn default_color_overrides() -> Option<BTreeMap<String, String>> {

src/util.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,6 @@ pub fn has_command(block_name: &str, command: &str) -> Result<bool> {
155155
Ok(exit_status.success())
156156
}
157157

158-
macro_rules! match_range {
159-
($a:expr, default: ($default:expr) {$($lower:expr ; $upper:expr => $e:expr),+}) => (
160-
match $a {
161-
$(
162-
t if t >= $lower && t <= $upper => { $e },
163-
)+
164-
_ => { $default }
165-
}
166-
)
167-
}
168-
169158
macro_rules! map (
170159
{ $($key:expr => $value:expr),+ } => {
171160
{

src/widgets/rotatingtext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl RotatingTextWidget {
163163
"separator_block_width": 0,
164164
"name" : self.id,
165165
"min_width":
166-
if self.content == "" {
166+
if self.content.is_empty() {
167167
"".to_string()
168168
} else {
169169
let text_width = self.get_rotated_content().chars().count();

0 commit comments

Comments
 (0)