From 48782ee421830bce662854860b95a1c2b2879618 Mon Sep 17 00:00:00 2001 From: Kent Gibson Date: Sat, 9 Mar 2024 16:57:28 +0800 Subject: [PATCH] use local var println formatting --- cli/CHANGELOG.md | 1 + cli/src/chip.rs | 2 +- cli/src/common.rs | 4 ++-- cli/src/main.rs | 2 +- cli/src/notify.rs | 6 +++--- cli/src/platform.rs | 4 ++-- cli/src/set.rs | 8 ++++---- lib/CHANGELOG.md | 2 ++ lib/examples/async_io_watch_line_value.rs | 2 +- lib/examples/async_std_watch_line_value.rs | 2 +- lib/examples/find_line_by_name.rs | 5 ++--- lib/examples/get_line_info.rs | 2 +- lib/examples/get_line_value.rs | 2 +- lib/examples/get_multiple_line_values.rs | 4 ++-- lib/examples/pulse_multiple_line_values.rs | 3 +-- lib/examples/toggle_line_value.rs | 5 ++--- lib/examples/toggle_multiple_line_values.rs | 2 +- lib/examples/tokio_ticking_watch_line_value.rs | 2 +- lib/src/lib.rs | 2 +- 19 files changed, 30 insertions(+), 30 deletions(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 8051296..e561732 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - remove dependency on nohash-hasher. +- use local var println formatting. diff --git a/cli/src/chip.rs b/cli/src/chip.rs index 846a5f6..0d3740c 100644 --- a/cli/src/chip.rs +++ b/cli/src/chip.rs @@ -104,7 +104,7 @@ impl CmdResults { ); } for e in &self.errors { - eprintln!("{}", e); + eprintln!("{e}"); } } } diff --git a/cli/src/common.rs b/cli/src/common.rs index fa6315b..aa26142 100644 --- a/cli/src/common.rs +++ b/cli/src/common.rs @@ -172,10 +172,10 @@ pub fn emit_error(opts: &EmitOpts, e: &anyhow::Error) { let e_str = format_error(opts, e); #[cfg(feature = "json")] if opts.json { - println!("{{\"error\":\"{}\"}}", e_str); + println!("{{\"error\":\"{e_str}\"}}"); return; } - eprintln!("{}", e_str); + eprintln!("{e_str}"); } pub fn format_error(opts: &EmitOpts, e: &anyhow::Error) -> String { diff --git a/cli/src/main.rs b/cli/src/main.rs index 3af2e65..17347fc 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -34,7 +34,7 @@ fn main() -> ExitCode { ExitCode::FAILURE }; } - Err(e) => eprintln!("{}", e), + Err(e) => eprintln!("{e}"), } ExitCode::FAILURE } diff --git a/cli/src/notify.rs b/cli/src/notify.rs index dae45c9..cf8faf0 100644 --- a/cli/src/notify.rs +++ b/cli/src/notify.rs @@ -248,7 +248,7 @@ impl CmdResults { return; } for e in &self.errors { - eprintln!("{}", e); + eprintln!("{e}"); } } @@ -328,9 +328,9 @@ impl Event { print!("{} {} ", ci.name, self.change.info.offset); } if opts.emit.quoted { - println!("\"{}\"", lname); + println!("\"{lname}\""); } else { - println!("{}", lname); + println!("{lname}"); } } else { println!("{} {}", ci.name, self.change.info.offset); diff --git a/cli/src/platform.rs b/cli/src/platform.rs index 462210b..27ae8b8 100644 --- a/cli/src/platform.rs +++ b/cli/src/platform.rs @@ -70,7 +70,7 @@ impl Platform { fn print(&self) { println!("Kernel {}", self.kernel.version); for e in &self.errors { - eprintln!("{}", e); + eprintln!("{e}"); } for abi in &self.abis { match abi.unsupported_by { @@ -82,7 +82,7 @@ impl Platform { println!("Kernel supports all {} features.", abi.version); } for f in &abi.missing_features { - println!("Kernel version does not support {}", f); + println!("Kernel version does not support {f}"); } } } diff --git a/cli/src/set.rs b/cli/src/set.rs index ce81932..597fb73 100644 --- a/cli/src/set.rs +++ b/cli/src/set.rs @@ -284,15 +284,15 @@ impl Setter { loop { match self.parse_command(&mut clcmd, &rl.readline()?) { Ok(am) => { - if let Err(err) = self.do_command(am, opts) { - println!("{}", err); + if let Err(e) = self.do_command(am, opts) { + println!("{e}"); // clean in case the error leaves dirty lines. self.clean(); return Ok(true); } } - Err(err) => { - println!("{}", err); + Err(e) => { + println!("{e}"); } } } diff --git a/lib/CHANGELOG.md b/lib/CHANGELOG.md index 8689309..010fba7 100644 --- a/lib/CHANGELOG.md +++ b/lib/CHANGELOG.md @@ -4,6 +4,8 @@ - remove dependency on `nohash-hasher`. - move adding attributes to v2::LineConfig to uapi. +- use local var println formatting. + diff --git a/lib/examples/async_io_watch_line_value.rs b/lib/examples/async_io_watch_line_value.rs index c87cf11..b2d8fef 100644 --- a/lib/examples/async_io_watch_line_value.rs +++ b/lib/examples/async_io_watch_line_value.rs @@ -22,7 +22,7 @@ fn main() -> Result<(), Box> { ); async_io::block_on(async { while let Ok(event) = req.read_edge_event().await { - println!("{:?}", event); + println!("{event:?}"); } }); Ok(()) diff --git a/lib/examples/async_std_watch_line_value.rs b/lib/examples/async_std_watch_line_value.rs index 8158ab7..d6a8e70 100644 --- a/lib/examples/async_std_watch_line_value.rs +++ b/lib/examples/async_std_watch_line_value.rs @@ -23,7 +23,7 @@ fn main() -> Result<(), Box> { ); async_std::task::block_on(async { while let Ok(event) = req.read_edge_event().await { - println!("{:?}", event); + println!("{event:?}"); } }); Ok(()) diff --git a/lib/examples/find_line_by_name.rs b/lib/examples/find_line_by_name.rs index bef413c..a06a678 100644 --- a/lib/examples/find_line_by_name.rs +++ b/lib/examples/find_line_by_name.rs @@ -9,12 +9,11 @@ fn main() { match gpiocdev::find_named_line(line_name) { Some(gpio22) => { println!( - "{}: {} {}", - line_name, + "{line_name}: {} {}", gpio22.chip.file_name().unwrap().to_string_lossy(), gpio22.info.offset ) } - None => println!("line {} not found", line_name), + None => println!("line {line_name} not found"), } } diff --git a/lib/examples/get_line_info.rs b/lib/examples/get_line_info.rs index 3bd47b6..a4cd29a 100644 --- a/lib/examples/get_line_info.rs +++ b/lib/examples/get_line_info.rs @@ -11,6 +11,6 @@ fn main() -> gpiocdev::Result<()> { let chip = gpiocdev::chip::Chip::from_path(chip_path)?; let info = chip.line_info(offset)?; - println!("{:?}", info); + println!("{info:?}"); Ok(()) } diff --git a/lib/examples/get_line_value.rs b/lib/examples/get_line_value.rs index 85a0050..70b75bb 100644 --- a/lib/examples/get_line_value.rs +++ b/lib/examples/get_line_value.rs @@ -20,7 +20,7 @@ fn main() -> Result<(), Box> { .request()?; let value = req.value(offset)?; - println!("{}={:?}", offset, value); + println!("{offset}={value}"); Ok(()) } diff --git a/lib/examples/get_multiple_line_values.rs b/lib/examples/get_multiple_line_values.rs index 2e42e72..72e62f0 100644 --- a/lib/examples/get_multiple_line_values.rs +++ b/lib/examples/get_multiple_line_values.rs @@ -20,11 +20,11 @@ fn main() -> Result<(), Box> { // get all requested line values at once let mut values = Values::default(); req.values(&mut values)?; - println!("all values = {:?}", values); + println!("all values = {values:?}"); // or individually let mut values = Values::from_offsets(&[23]); req.values(&mut values)?; - println!("one value = {:?}", values); + println!("one value = {values:?}"); Ok(()) } diff --git a/lib/examples/pulse_multiple_line_values.rs b/lib/examples/pulse_multiple_line_values.rs index d0cc887..05c700e 100644 --- a/lib/examples/pulse_multiple_line_values.rs +++ b/lib/examples/pulse_multiple_line_values.rs @@ -7,7 +7,6 @@ use gpiocdev::line::{Value, Values}; use gpiocdev::Request; use std::result::Result; -use std::thread; use std::time::Duration; fn main() -> Result<(), Box> { @@ -20,7 +19,7 @@ fn main() -> Result<(), Box> { .request()?; // some time later... - thread::sleep(Duration::from_secs(2)); + std::thread::sleep(Duration::from_secs(2)); // change the values at once... let mut values = Values::default(); diff --git a/lib/examples/toggle_line_value.rs b/lib/examples/toggle_line_value.rs index a61d8c9..992d767 100644 --- a/lib/examples/toggle_line_value.rs +++ b/lib/examples/toggle_line_value.rs @@ -8,7 +8,6 @@ use anyhow::Context; use gpiocdev::line::Value; use gpiocdev::Request; use std::result::Result; -use std::thread; use std::time::Duration; fn main() -> Result<(), Box> { @@ -24,8 +23,8 @@ fn main() -> Result<(), Box> { .context("Failed to request line")?; loop { - println!("{}={:?}", offset, value); - thread::sleep(Duration::from_millis(500)); + println!("{offset}={value}"); + std::thread::sleep(Duration::from_millis(500)); value = value.not(); req.set_value(offset, value) .context("Failed to set value")?; diff --git a/lib/examples/toggle_multiple_line_values.rs b/lib/examples/toggle_multiple_line_values.rs index 4937b85..0fc18c0 100644 --- a/lib/examples/toggle_multiple_line_values.rs +++ b/lib/examples/toggle_multiple_line_values.rs @@ -27,7 +27,7 @@ fn main() -> Result<(), Box> { .context("Failed to request line")?; loop { - println!("{:?}", values); + println!("{values:?}"); thread::sleep(Duration::from_millis(500)); values.not(); req.set_values(&values).context("Failed to set values")?; diff --git a/lib/examples/tokio_ticking_watch_line_value.rs b/lib/examples/tokio_ticking_watch_line_value.rs index 7421842..22944d0 100644 --- a/lib/examples/tokio_ticking_watch_line_value.rs +++ b/lib/examples/tokio_ticking_watch_line_value.rs @@ -26,7 +26,7 @@ async fn main() -> Result<(), Box> { loop { tokio::select! { Some(Ok(event)) = events.next() => { - println!("{:?}", event); + println!("{event:?}"); } _ = ticker.tick() => { let elapsed_time = now.elapsed(); diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 0c670d2..58656d7 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -42,7 +42,7 @@ //! .with_debounce_period(std::time::Duration::from_millis(5)) //! .request()?; //! for edge in req.edge_events() { -//! println!("{:?}", edge); +//! println!("{edge:?}"); //! } //! # Ok(()) //! # }