Skip to content

Commit 10722bf

Browse files
committed
tools: Fix clippy lints
1 parent 79d6bec commit 10722bf

File tree

5 files changed

+43
-54
lines changed

5 files changed

+43
-54
lines changed

tools/src/bin/run-fap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn main() -> Result<(), Error> {
8989

9090
let port_info =
9191
serial::find_flipperzero(cli.port.as_deref()).ok_or(Error::FlipperZeroNotFound)?;
92-
let port = serialport::new(&port_info.port_name, serial::BAUD_115200)
92+
let port = serialport::new(port_info.port_name, serial::BAUD_115200)
9393
.timeout(Duration::from_secs(30))
9494
.open()
9595
.map_err(Error::FailedToOpenSerialPort)?;

tools/src/bin/serial_cli.rs

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() -> io::Result<()> {
2828

2929
let port_info =
3030
serial::find_flipperzero(cli.port.as_deref()).expect("unable to find Flipper Zero");
31-
let mut port = serialport::new(&port_info.port_name, serial::BAUD_115200)
31+
let mut port = serialport::new(port_info.port_name, serial::BAUD_115200)
3232
.timeout(Duration::from_millis(10))
3333
.open()
3434
.expect("unable to open serial port");
@@ -58,7 +58,7 @@ fn run(port: &mut dyn serialport::SerialPort) -> io::Result<()> {
5858
match port.read(&mut buf) {
5959
Err(err) => {
6060
if err.kind() != io::ErrorKind::TimedOut {
61-
return Err(err.into());
61+
return Err(err);
6262
}
6363
}
6464
Ok(count) => {
@@ -69,41 +69,39 @@ fn run(port: &mut dyn serialport::SerialPort) -> io::Result<()> {
6969

7070
while crossterm::event::poll(Duration::ZERO)? {
7171
let event = crossterm::event::read()?;
72-
match event {
73-
Event::Key(KeyEvent {
74-
code,
75-
modifiers,
76-
kind,
77-
..
78-
}) => {
79-
if kind == KeyEventKind::Release {
80-
continue;
81-
}
72+
if let Event::Key(KeyEvent {
73+
code,
74+
modifiers,
75+
kind,
76+
..
77+
}) = event
78+
{
79+
if kind == KeyEventKind::Release {
80+
continue;
81+
}
8282

83-
match (modifiers, code) {
84-
// MacOS converts Ctrl+] to Ctrl+5
85-
(KeyModifiers::CONTROL, KeyCode::Char(']') | KeyCode::Char('5')) => {
86-
eprintln!("Exiting...");
87-
return Ok(());
88-
}
89-
(KeyModifiers::CONTROL, KeyCode::Char('c')) => write!(port, "{ETXT}")?,
90-
(KeyModifiers::SHIFT, KeyCode::Char(c)) => {
91-
write!(port, "{c}")?;
92-
}
93-
(KeyModifiers::NONE, KeyCode::Char(c)) => {
94-
write!(port, "{c}")?;
95-
}
96-
(KeyModifiers::NONE, KeyCode::Backspace) => {
97-
write!(port, "{DEL}")?;
98-
}
99-
(KeyModifiers::NONE, KeyCode::Enter) => {
100-
write!(port, "\r\n")?;
101-
}
102-
_ => (),
83+
match (modifiers, code) {
84+
// MacOS converts Ctrl+] to Ctrl+5
85+
(KeyModifiers::CONTROL, KeyCode::Char(']') | KeyCode::Char('5')) => {
86+
eprintln!("Exiting...");
87+
return Ok(());
88+
}
89+
(KeyModifiers::CONTROL, KeyCode::Char('c')) => write!(port, "{ETXT}")?,
90+
(KeyModifiers::SHIFT, KeyCode::Char(c)) => {
91+
write!(port, "{c}")?;
92+
}
93+
(KeyModifiers::NONE, KeyCode::Char(c)) => {
94+
write!(port, "{c}")?;
10395
}
96+
(KeyModifiers::NONE, KeyCode::Backspace) => {
97+
write!(port, "{DEL}")?;
98+
}
99+
(KeyModifiers::NONE, KeyCode::Enter) => {
100+
write!(port, "\r\n")?;
101+
}
102+
_ => (),
104103
}
105-
_ => (),
106-
};
104+
}
107105

108106
port.flush()?;
109107
}

tools/src/bin/storage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn main() {
8383

8484
let port_info =
8585
serial::find_flipperzero(cli.port.as_deref()).expect("unable to find Flipper Zero");
86-
let port = serialport::new(&port_info.port_name, serial::BAUD_115200)
86+
let port = serialport::new(port_info.port_name, serial::BAUD_115200)
8787
.timeout(Duration::from_secs(30))
8888
.open()
8989
.expect("unable to open serial port");
@@ -107,7 +107,7 @@ fn main() {
107107
Commands::Receive {
108108
flipper_path,
109109
local_path,
110-
} => store.receive_file(flipper_path, &local_path),
110+
} => store.receive_file(flipper_path, local_path),
111111
Commands::Send {
112112
local_path,
113113
flipper_path,

tools/src/serial.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ pub fn find_flipperzero(port_name: Option<&str>) -> Option<SerialPortInfo> {
2626
p.port_name == port
2727
} else {
2828
// Auto-detect port
29-
match &p.port_type {
30-
SerialPortType::UsbPort(usb) if (usb.vid, usb.pid) == HWID => true,
31-
_ => false,
32-
}
29+
matches!(&p.port_type, SerialPortType::UsbPort(usb) if (usb.vid, usb.pid) == HWID)
3330
}
3431
})
3532
}

tools/src/storage.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ impl FlipperStorage {
5454
.send_and_wait_eol(&format!("storage list {}", path))?;
5555

5656
let data = self.cli.read_until_prompt()?;
57-
for line in CLI_EOL
58-
.split(&data)
59-
.map(|line| String::from_utf8_lossy(line))
60-
{
57+
for line in CLI_EOL.split(&data).map(String::from_utf8_lossy) {
6158
let line = line.trim();
6259
if line.is_empty() {
6360
continue;
@@ -72,7 +69,7 @@ impl FlipperStorage {
7269
continue;
7370
}
7471

75-
if let Some((typ, info)) = line.split_once(" ") {
72+
if let Some((typ, info)) = line.split_once(' ') {
7673
match typ {
7774
// Directory
7875
"[D]" => {
@@ -83,7 +80,7 @@ impl FlipperStorage {
8380
}
8481
// File
8582
"[F]" => {
86-
if let Some((name, size)) = info.rsplit_once(" ") {
83+
if let Some((name, size)) = info.rsplit_once(' ') {
8784
let path = path.clone() + name;
8885

8986
eprintln!("{path}, size {size}");
@@ -101,7 +98,7 @@ impl FlipperStorage {
10198
/// Send local file to the device.
10299
pub fn send_file(&mut self, from: impl AsRef<Path>, to: &FlipperPath) -> io::Result<()> {
103100
// Try to create directory on Flipper
104-
if let Some(dir) = to.0.rsplit_once("/") {
101+
if let Some(dir) = to.0.rsplit_once('/') {
105102
self.mkdir(&FlipperPath::from(dir.0)).ok();
106103
}
107104
self.remove(to).ok();
@@ -162,12 +159,9 @@ impl FlipperStorage {
162159
let (_, size) = line
163160
.split_once(": ")
164161
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "failed to read chunk size"))?;
165-
let size: usize = size.parse().or_else(|_| {
166-
Err(io::Error::new(
167-
io::ErrorKind::Other,
168-
"failed to parse chunk size",
169-
))
170-
})?;
162+
let size: usize = size
163+
.parse()
164+
.map_err(|_| io::Error::new(io::ErrorKind::Other, "failed to parse chunk size"))?;
171165

172166
let mut data = BytesMut::with_capacity(BUF_SIZE);
173167

0 commit comments

Comments
 (0)