Skip to content

Commit 64fcdeb

Browse files
authored
rofication-block: Solve clippy messages (#1365)
1 parent e83960a commit 64fcdeb

File tree

1 file changed

+16
-43
lines changed

1 file changed

+16
-43
lines changed

src/blocks/rofication.rs

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::str::FromStr;
21
use std::time::Duration;
32

43
use crossbeam_channel::Sender;
@@ -72,7 +71,7 @@ impl ConfigBlock for Rofication {
7271
shared_config: SharedConfig,
7372
_tx_update_request: Sender<Task>,
7473
) -> Result<Self> {
75-
let text = TextWidget::new(id, 0, shared_config.clone())
74+
let text = TextWidget::new(id, 0, shared_config)
7675
.with_text("?")
7776
.with_icon("bell")?
7877
.with_state(State::Good);
@@ -98,12 +97,10 @@ impl Block for Rofication {
9897
self.text.set_texts(self.format.render(&values)?);
9998
if status.crit > 0 {
10099
self.text.set_state(State::Critical)
100+
} else if status.num > 0 {
101+
self.text.set_state(State::Warning)
101102
} else {
102-
if status.num > 0 {
103-
self.text.set_state(State::Warning)
104-
} else {
105-
self.text.set_state(State::Good)
106-
}
103+
self.text.set_state(State::Good)
107104
}
108105
self.text.set_icon("bell")?;
109106
}
@@ -148,27 +145,15 @@ fn rofication_status(socket_path: &str) -> Result<RotificationStatus> {
148145
};
149146

150147
// Request count
151-
match stream.write(b"num\n") {
152-
Err(_) => {
153-
return Err(BlockError(
154-
"rofication".to_string(),
155-
"Failed to write to socket".to_string(),
156-
))
157-
}
158-
Ok(_) => {}
159-
};
148+
stream
149+
.write(b"num\n")
150+
.block_error("rofication", "Failed to write to socket")?;
160151

161152
// Response must be two comma separated integers: regular and critical
162153
let mut buffer = String::new();
163-
match stream.read_to_string(&mut buffer) {
164-
Err(_) => {
165-
return Err(BlockError(
166-
"rofication".to_string(),
167-
"Failed to read from socket".to_string(),
168-
))
169-
}
170-
Ok(_) => {}
171-
};
154+
stream
155+
.read_to_string(&mut buffer)
156+
.block_error("rofication", "Failed to read from socket")?;
172157

173158
let values = buffer.split(',').collect::<Vec<&str>>();
174159
if values.len() != 2 {
@@ -178,24 +163,12 @@ fn rofication_status(socket_path: &str) -> Result<RotificationStatus> {
178163
));
179164
}
180165

181-
let num = match values[0].parse::<u64>() {
182-
Ok(num) => num,
183-
Err(_) => {
184-
return Err(BlockError(
185-
"rofication".to_string(),
186-
"Failed to parse num".to_string(),
187-
))
188-
}
189-
};
190-
let crit = match values[1].parse::<u64>() {
191-
Ok(crit) => crit,
192-
Err(_) => {
193-
return Err(BlockError(
194-
"rofication".to_string(),
195-
"Failed to parse crit".to_string(),
196-
))
197-
}
198-
};
166+
let num = values[0]
167+
.parse::<u64>()
168+
.block_error("rofication", "Failed to parse num")?;
169+
let crit = values[1]
170+
.parse::<u64>()
171+
.block_error("rofication", "Failed to parse crit")?;
199172

200173
Ok(RotificationStatus { num, crit })
201174
}

0 commit comments

Comments
 (0)