Skip to content

Commit

Permalink
use local var println formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
warthog618 committed Mar 10, 2024
1 parent 0083606 commit 48782ee
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 30 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- remove dependency on nohash-hasher.
- use local var println formatting.

<a name="v0.5.3"></a>

Expand Down
2 changes: 1 addition & 1 deletion cli/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl CmdResults {
);
}
for e in &self.errors {
eprintln!("{}", e);
eprintln!("{e}");
}
}
}
4 changes: 2 additions & 2 deletions cli/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn main() -> ExitCode {
ExitCode::FAILURE
};
}
Err(e) => eprintln!("{}", e),
Err(e) => eprintln!("{e}"),
}
ExitCode::FAILURE
}
Expand Down
6 changes: 3 additions & 3 deletions cli/src/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl CmdResults {
return;
}
for e in &self.errors {
eprintln!("{}", e);
eprintln!("{e}");
}
}

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions cli/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}");
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions cli/src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- remove dependency on `nohash-hasher`.
- move adding attributes to v2::LineConfig to uapi.
- use local var println formatting.


<a name="v0.7.0"></a>

Expand Down
2 changes: 1 addition & 1 deletion lib/examples/async_io_watch_line_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
);
async_io::block_on(async {
while let Ok(event) = req.read_edge_event().await {
println!("{:?}", event);
println!("{event:?}");
}
});
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion lib/examples/async_std_watch_line_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
);
async_std::task::block_on(async {
while let Ok(event) = req.read_edge_event().await {
println!("{:?}", event);
println!("{event:?}");
}
});
Ok(())
Expand Down
5 changes: 2 additions & 3 deletions lib/examples/find_line_by_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
2 changes: 1 addition & 1 deletion lib/examples/get_line_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
2 changes: 1 addition & 1 deletion lib/examples/get_line_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.request()?;

let value = req.value(offset)?;
println!("{}={:?}", offset, value);
println!("{offset}={value}");

Ok(())
}
4 changes: 2 additions & 2 deletions lib/examples/get_multiple_line_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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(())
}
3 changes: 1 addition & 2 deletions lib/examples/pulse_multiple_line_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
Expand All @@ -20,7 +19,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.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();
Expand Down
5 changes: 2 additions & 3 deletions lib/examples/toggle_line_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
Expand All @@ -24,8 +23,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.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")?;
Expand Down
2 changes: 1 addition & 1 deletion lib/examples/toggle_multiple_line_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.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")?;
Expand Down
2 changes: 1 addition & 1 deletion lib/examples/tokio_ticking_watch_line_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
loop {
tokio::select! {
Some(Ok(event)) = events.next() => {
println!("{:?}", event);
println!("{event:?}");
}
_ = ticker.tick() => {
let elapsed_time = now.elapsed();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
//! # }
Expand Down

0 comments on commit 48782ee

Please sign in to comment.