bindings: rust: fix clippy warnings
cover bindings: rust: fix clippy warnings
This fixes warnings reported by clippy 0.1.88.
---
Erik Wierich (2):
bindings: rust: remove newline between attribute and attribute
bindings: rust: simplify format statements
bindings/rust/libgpiod-sys/src/lib.rs | 1 - bindings/rust/libgpiod/examples/find_line_by_name.rs | 2 +- bindings/rust/libgpiod/examples/get_line_info.rs | 3 +-- bindings/rust/libgpiod/examples/get_line_value.rs | 2 +- bindings/rust/libgpiod/examples/get_multiple_line_values.rs | 2 +- bindings/rust/libgpiod/examples/reconfigure_input_to_output.rs | 4 ++-- bindings/rust/libgpiod/examples/toggle_line_value.rs | 2 +- bindings/rust/libgpiod/src/lib.rs | 4 ++-- 8 files changed, 9 insertions(+), 11 deletions(-)
---
base-commit: e4427590d9d63a7104dd5df564dd6b7b0c784547
change-id: 20250721-rust-clippy-df73580f6624
Best regards,
Signature · 1 line
Erik Wierich <[email protected]>
PATCH 1/2 bindings: rust: remove newline between attribute and attribute
These are block attributes, but the newline in between suggests that they are for the whole module.
Fixes clippy warning:
warning: empty line after outer attribute
--> libgpiod-sys/src/lib.rs:6:1
|
6 | / #[cfg_attr(test, allow(deref_nullptr, non_snake_case))]
7 | |
| |_^
8 | mod bindings_raw {
| ---------------- the attribute applies to this module
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_outer_attr
= note: `#[warn(clippy::empty_line_after_outer_attr)]` on by default
= help: if the empty line is unintentional, remove it
help: if the attribute should apply to the crate use an inner attribute
|
5 ~ #![allow(non_camel_case_types, non_upper_case_globals)]
6 ~ #![cfg_attr(test, allow(deref_nullptr, non_snake_case))]
|--- bindings/rust/libgpiod-sys/src/lib.rs | 1 - 1 file changed, 1 deletion(-)
bindings/rust/libgpiod-sys/src/lib.rs +0 -1
@@ -1,11 +1,10 @@// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause // SPDX-FileCopyrightText: 2022 Linaro Ltd. // SPDX-FileCopyrightText: 2022 Viresh Kumar <[email protected]> #[allow(non_camel_case_types, non_upper_case_globals)] #[cfg_attr(test, allow(deref_nullptr, non_snake_case))] -mod bindings_raw {include! (concat! (env! ("OUT_DIR" ),"/bindings.rs" )); }pub use bindings_raw::*;
Signature · 1 line
2.50.0
PATCH 2/2 bindings: rust: simplify format statements
In reply to Erik Wierichclippy suggested these:
warning: variables can be used directly in the `format!` string
--> libgpiod/src/lib.rs:113:9
|
113 | write!(f, "{:?}", self)
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
= note: `#[warn(clippy::uninlined_format_args)]` on by default
help: change this to
|
113 - write!(f, "{:?}", self)
113 + write!(f, "{self:?}")
|Generated with cargo clippy --fix.
The suggestions look like an improvement to me.
--- bindings/rust/libgpiod/examples/find_line_by_name.rs | 2 +- bindings/rust/libgpiod/examples/get_line_info.rs | 3 +-- bindings/rust/libgpiod/examples/get_line_value.rs | 2 +- bindings/rust/libgpiod/examples/get_multiple_line_values.rs | 2 +- bindings/rust/libgpiod/examples/reconfigure_input_to_output.rs | 4 ++-- bindings/rust/libgpiod/examples/toggle_line_value.rs | 2 +- bindings/rust/libgpiod/src/lib.rs | 4 ++-- 7 files changed, 9 insertions(+), 10 deletions(-)
bindings/rust/libgpiod/examples/find_line_by_name.rs +1 -1
@@ -20,10 +20,10 @@ fn main() -> libgpiod::Result<()> { info.name()?, offset? );return Ok (()); } } -println! ("line '{}' not found" , line_name); +println! ("line '{line_name}' not found" );Ok (()) }
bindings/rust/libgpiod/examples/get_line_info.rs +1 -2
@@ -25,13 +25,12 @@ fn main() -> libgpiod::Result<()> {let low =if info.is_active_low () {"active-low" }else {"active-high" };println! ( -"line {:>3}: {:>12} {:>12} {:>8} {:>10}" , - line_offset, name, consumer, dir, low +"line {line_offset:>3}: {name:>12} {consumer:>12} {dir:>8} {low:>10}" );Ok (()) }
bindings/rust/libgpiod/examples/get_line_value.rs +1 -1
@@ -19,10 +19,10 @@ fn main() -> libgpiod::Result<()> {let mut rconfig = libgpiod::request::Config ::new ()?; rconfig.set_consumer ("get-line-value" )?;let chip = libgpiod::chip::Chip ::open (&chip_path)?;let request = chip.request_lines (Some (&rconfig), &lconfig)?;let value = request.value (line_offset)?; -println! ("{}={:?}" , line_offset, value); +println! ("{line_offset}={value:?}" );Ok (()) }
bindings/rust/libgpiod/examples/get_multiple_line_values.rs +1 -1
@@ -20,10 +20,10 @@ fn main() -> libgpiod::Result<()> {let mut rconfig = libgpiod::request::Config ::new ()?; rconfig.set_consumer ("get-multiple-line-values" )?;let request = chip.request_lines (Some (&rconfig), &lconfig)?;let values = request.values ()?; -println! ("{:?}" , values); +println! ("{values:?}" );Ok (()) }
bindings/rust/libgpiod/examples/reconfigure_input_to_output.rs +2 -2
@@ -21,22 +21,22 @@ fn main() -> libgpiod::Result<()> {let chip = libgpiod::chip::Chip ::open (&chip_path)?;// request the line initially as an input let mut request = chip.request_lines (Some (&rconfig), &lconfig)?;// read the current line value let value = request.value (line_offset)?; -println! ("{}={:?} (input)" , line_offset, value); +println! ("{line_offset}={value:?} (input)" );// switch the line to an output and drive it low let mut lsettings = line::Settings ::new ()?; lsettings.set_direction (line::Direction ::Output )?; lsettings.set_output_value (line::Value ::InActive )?; lconfig.add_line_settings (&[line_offset], lsettings)?; request.reconfigure_lines (&lconfig)?;// report the current driven value let value = request.value (line_offset)?; -println! ("{}={:?} (output)" , line_offset, value); +println! ("{line_offset}={value:?} (output)" );Ok (()) }
bindings/rust/libgpiod/examples/toggle_line_value.rs +1 -1
@@ -30,13 +30,13 @@ fn main() -> libgpiod::Result<()> {let mut rconfig = libgpiod::request::Config ::new ()?; rconfig.set_consumer ("toggle-line-value" )?;let chip = libgpiod::chip::Chip ::open (&chip_path)?;let mut req = chip.request_lines (Some (&rconfig), &lconfig)?;loop { -println! ("{}={:?}" , line_offset, value); +println! ("{line_offset}={value:?}" ); std::thread::sleep (Duration ::from_secs (1 )); value =toggle_value (value); req.set_value (line_offset, value)?; } }
bindings/rust/libgpiod/src/lib.rs +2 -2
@@ -106,15 +106,15 @@ pub enum OperationType { SimDevNew, SimDevEnable, SimDevDisable, }impl fmt::Display for OperationType {fn fmt (&self, f: &mut fmt::Formatter <'_>) -> fmt::Result { -write! (f,"{:?}" , self) +write! (f,"{self:?}" ) } }/// Result of libgpiod operations. pub type Result <T > = std::result::Result <T ,Error >;/// Error codes for libgpiod operations.
@@ -378,15 +378,15 @@ pub mod line { EventClock(EventClock),/// Output value. OutputValue(Value), }impl fmt::Display for SettingVal {fn fmt (&self, f: &mut fmt::Formatter <'_>) -> fmt::Result { -write! (f,"{:?}" , self) +write! (f,"{self:?}" ) } }/// Event clock settings. #[derive( Copy , Clone , Debug , Eq , PartialEq )] pub enum EventClock {/// Line uses the monotonic clock for edge event timestamps.
Signature · 1 line
2.50.0
Quoted 7 lines · Erik Wierich
This fixes warnings reported by clippy 0.1.88.
Signed-off-by Erik Wierich <[email protected]>---
Erik Wierich (2):
bindings: rust: remove newline between attribute and attribute
bindings: rust: simplify format statements
Signature · 1 line
viresh
Bartosz Golaszewski
AppliedFrom: Bartosz Golaszewski <[email protected]>
Quoted 3 lines · Erik Wierich
This fixes warnings reported by clippy 0.1.88.
Applied, thanks!
[1/2] bindings: rust: remove newline between attribute and attribute
commit: b20401360ce35fabc123c379ab3fddb394ee467e
[2/2] bindings: rust: simplify format statements
commit: 6263abf3abb6fcdb4b85745664a7bb3c1d3c4f8cBest regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>