Skip to content

Commit

Permalink
Fix some issues pointed out by Clippy in examples and tests (#172)
Browse files Browse the repository at this point in the history
In case of writing data, the code looks like it expects all data to be
written. And in case of reading data it expects some data to be read.
Let's make this explicit.
  • Loading branch information
sirhcel authored Mar 28, 2024
1 parent 84f6066 commit 361664b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/clear_input_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn input_service() -> mpsc::Receiver<()> {
drop(tx); // EOF, drop the channel and stop the thread
break;
}
Ok(_) => tx.send(()).unwrap(), // Signal main to clear the buffer
Ok(_bytes_read) => tx.send(()).unwrap(), // Signal main to clear the buffer
Err(e) => panic_any(e),
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/clear_output_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn run(port_name: &str, baud_rate: &str, block_size: usize) -> Result<(), Box<dy
// This loop writes the block repeatedly, as fast as possible, to try to saturate the
// output buffer. If you don't see much data queued to send, try changing the block size.
loop {
match port.write(&block) {
match port.write_all(&block) {
Ok(_) => (),
Err(ref e) if e.kind() == io::ErrorKind::TimedOut => (),
Err(e) => panic!("Error while writing data to the port: {}", e),
Expand Down Expand Up @@ -125,7 +125,7 @@ fn input_service() -> mpsc::Receiver<()> {
drop(tx); // EOF, drop the channel and stop the thread
break;
}
Ok(_) => tx.send(()).unwrap(), // Signal main to clear the buffer
Ok(_bytes_read) => tx.send(()).unwrap(), // Signal main to clear the buffer
Err(e) => panic_any(e),
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn test_osx_pty_pair() {
let (output_sink, output_stream) = std::sync::mpsc::sync_channel(1);
let name = slave.name().unwrap();

master.write("12".as_bytes()).expect("");
master.write_all("12".as_bytes()).expect("");

let reader_thread = std::thread::spawn(move || {
let mut port = TTYPort::open(&serialport::new(&name, 0)).expect("unable to open");
Expand Down

0 comments on commit 361664b

Please sign in to comment.