From c1b78e9014e3d45c0b90a74bb151b1ec0ef6819f Mon Sep 17 00:00:00 2001 From: Rahix Date: Sat, 20 Jan 2024 22:33:06 +0100 Subject: [PATCH] ravedude: Apply rustfmt --- ravedude/src/board.rs | 21 ++++++++------------- ravedude/src/console.rs | 5 +++-- ravedude/src/main.rs | 14 +++++--------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/ravedude/src/board.rs b/ravedude/src/board.rs index dd8dca0bca..3882b56045 100644 --- a/ravedude/src/board.rs +++ b/ravedude/src/board.rs @@ -170,16 +170,14 @@ impl Board for ArduinoLeonardo { fn needs_reset(&self) -> Option<&str> { let a = self.guess_port(); match a { - Some(Ok(name)) => { - match serialport::new(name.to_str().unwrap(), 1200).open() { - Ok(_) => { - std::thread::sleep(core::time::Duration::from_secs(1)); - None - }, - Err(_) => Some("Reset the board by pressing the reset button once.") + Some(Ok(name)) => match serialport::new(name.to_str().unwrap(), 1200).open() { + Ok(_) => { + std::thread::sleep(core::time::Duration::from_secs(1)); + None } + Err(_) => Some("Reset the board by pressing the reset button once."), }, - _ => Some("Reset the board by pressing the reset button once.") + _ => Some("Reset the board by pressing the reset button once."), } } @@ -202,7 +200,6 @@ impl Board for ArduinoLeonardo { } } - struct ArduinoMega1280; impl Board for ArduinoMega1280 { @@ -224,12 +221,11 @@ impl Board for ArduinoMega1280 { } fn guess_port(&self) -> Option> { - // This board uses a generic serial interface id 0403:6001 which is too common for auto detection. - Some(Err(anyhow::anyhow!("Unable to guess port."))) + // This board uses a generic serial interface id 0403:6001 which is too common for auto detection. + Some(Err(anyhow::anyhow!("Unable to guess port."))) } } - struct ArduinoMega2560; impl Board for ArduinoMega2560 { @@ -417,7 +413,6 @@ impl Board for Nano168 { } } - struct ArduinoDuemilanove; impl Board for ArduinoDuemilanove { diff --git a/ravedude/src/console.rs b/ravedude/src/console.rs index 42cc5c54e7..f09c51b162 100644 --- a/ravedude/src/console.rs +++ b/ravedude/src/console.rs @@ -17,7 +17,8 @@ pub fn open(port: &std::path::Path, baudrate: u32) -> anyhow::Result<()> { eprintln!(""); eprintln!("Exiting."); std::process::exit(0); - }).context("failed setting a CTRL+C handler")?; + }) + .context("failed setting a CTRL+C handler")?; // Spawn a thread for the receiving end because stdio is not portably non-blocking... std::thread::spawn(move || loop { @@ -27,7 +28,7 @@ pub fn open(port: &std::path::Path, baudrate: u32) -> anyhow::Result<()> { // Use buffer size 1 for windows because it blocks on rx.read until the buffer is full #[cfg(target_os = "windows")] let mut buf = [0u8; 1]; - + match rx.read(&mut buf) { Ok(count) => { stdout.write(&buf[..count]).unwrap(); diff --git a/ravedude/src/main.rs b/ravedude/src/main.rs index 6973278b43..066c39e728 100644 --- a/ravedude/src/main.rs +++ b/ravedude/src/main.rs @@ -2,8 +2,8 @@ use anyhow::Context as _; use colored::Colorize as _; use structopt::clap::AppSettings; -use std::time::Duration; use std::thread; +use std::time::Duration; mod avrdude; mod board; @@ -94,15 +94,15 @@ fn ravedude() -> anyhow::Result<()> { task_message!("Board", "{}", board.display_name()); - if let Some(wait_time) = args.reset_delay{ + if let Some(wait_time) = args.reset_delay { if wait_time > 0 { println!("Waiting {} ms before proceeding", wait_time); let wait_time = Duration::from_millis(wait_time); thread::sleep(wait_time); - }else{ + } else { println!("Assuming board has been reset"); } - }else{ + } else { if let Some(msg) = board.needs_reset() { warning!("this board cannot reset itself."); eprintln!(""); @@ -157,11 +157,7 @@ fn ravedude() -> anyhow::Result<()> { let port = port.context("console can only be opened for devices with USB-to-Serial")?; task_message!("Console", "{} at {} baud", port.display(), baudrate); - task_message!( - "", - "{}", - "CTRL+C to exit.".dimmed() - ); + task_message!("", "{}", "CTRL+C to exit.".dimmed()); // Empty line for visual consistency eprintln!(); console::open(&port, baudrate)?;