* [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks
@ 2025-09-26 14:35 Bartosz Golaszewski
2025-09-26 14:35 ` [PATCH libgpiod 1/3] bindings: rust: complete the unification of exports in examples Bartosz Golaszewski
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Bartosz Golaszewski @ 2025-09-26 14:35 UTC (permalink / raw)
To: Erik Wierich, Viresh Kumar, Linus Walleij; +Cc: linux-gpio, Bartosz Golaszewski
Here are some final tweaks before I do the 1.0.0 release of libgpiod
rust crates. The first patch completes what I though I already did last
time when updating the examples but I must have borked. The second patch
just runs `rustfmt --edition 2024` on all source files. Finally the last
patch adds some examples to the readme so that the landing page on
crates.io already shows how to use the code.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
Bartosz Golaszewski (3):
bindings: rust: complete the unification of exports in examples
bindings: rust: update formatting to --edition 2024
bindings: rust: add examples to the README.md in the libgpiod crate
bindings/rust/gpiosim-sys/src/lib.rs | 2 +-
bindings/rust/gpiosim-sys/src/sim.rs | 2 +-
bindings/rust/libgpiod/README.md | 78 ++++++++++++++
.../libgpiod/examples/buffered_event_lifetimes.rs | 2 +-
.../rust/libgpiod/examples/find_line_by_name.rs | 2 +-
bindings/rust/libgpiod/examples/get_chip_info.rs | 2 +-
bindings/rust/libgpiod/examples/get_line_info.rs | 2 +-
bindings/rust/libgpiod/examples/get_line_value.rs | 2 +-
.../libgpiod/examples/get_multiple_line_values.rs | 2 +-
.../examples/reconfigure_input_to_output.rs | 2 +-
.../rust/libgpiod/examples/toggle_line_value.rs | 17 +--
.../examples/toggle_multiple_line_values.rs | 17 +--
bindings/rust/libgpiod/examples/watch_line_info.rs | 2 +-
.../rust/libgpiod/examples/watch_line_rising.rs | 23 ++--
.../rust/libgpiod/examples/watch_line_value.rs | 25 +++--
.../examples/watch_multiple_line_values.rs | 18 ++--
bindings/rust/libgpiod/src/chip.rs | 4 +-
bindings/rust/libgpiod/src/edge_event.rs | 3 +-
bindings/rust/libgpiod/src/event_buffer.rs | 3 +-
bindings/rust/libgpiod/src/info_event.rs | 3 +-
bindings/rust/libgpiod/src/lib.rs | 2 +-
bindings/rust/libgpiod/src/line_config.rs | 3 +-
bindings/rust/libgpiod/src/line_info.rs | 3 +-
bindings/rust/libgpiod/src/line_request.rs | 4 +-
bindings/rust/libgpiod/src/line_settings.rs | 3 +-
bindings/rust/libgpiod/src/request_config.rs | 2 +-
bindings/rust/libgpiod/tests/chip.rs | 2 +-
bindings/rust/libgpiod/tests/common/config.rs | 3 +-
bindings/rust/libgpiod/tests/edge_event.rs | 120 ++++++++++++---------
bindings/rust/libgpiod/tests/info_event.rs | 58 +++++-----
bindings/rust/libgpiod/tests/line_info.rs | 2 +-
bindings/rust/libgpiod/tests/line_request.rs | 12 ++-
bindings/rust/libgpiod/tests/request_config.rs | 2 +-
33 files changed, 276 insertions(+), 151 deletions(-)
---
base-commit: 97ee30872853b2c9fbb448240012909d985f2e19
change-id: 20250925-rust-release-tweaks-d1a94bfda0c4
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH libgpiod 1/3] bindings: rust: complete the unification of exports in examples
2025-09-26 14:35 [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks Bartosz Golaszewski
@ 2025-09-26 14:35 ` Bartosz Golaszewski
2025-09-29 6:21 ` Erik Schilling
2025-09-26 14:35 ` [PATCH libgpiod 2/3] bindings: rust: update formatting to --edition 2024 Bartosz Golaszewski
` (4 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Bartosz Golaszewski @ 2025-09-26 14:35 UTC (permalink / raw)
To: Erik Wierich, Viresh Kumar, Linus Walleij; +Cc: linux-gpio, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Commit cd32f27dd550 ("bindings: rust: unify imports in examples") failed
to consistently unify the code across all examples so finish the
process.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
.../rust/libgpiod/examples/toggle_line_value.rs | 17 +++++++++------
.../examples/toggle_multiple_line_values.rs | 17 +++++++++------
.../rust/libgpiod/examples/watch_line_rising.rs | 23 ++++++++++++--------
.../rust/libgpiod/examples/watch_line_value.rs | 25 +++++++++++++---------
.../examples/watch_multiple_line_values.rs | 18 +++++++++-------
5 files changed, 59 insertions(+), 41 deletions(-)
diff --git a/bindings/rust/libgpiod/examples/toggle_line_value.rs b/bindings/rust/libgpiod/examples/toggle_line_value.rs
index 8d34c5fa18746bc89fe6597f22a77c000a6b49c6..33b17d5a36364f4a0e9e93c0f68570f764fc31a4 100644
--- a/bindings/rust/libgpiod/examples/toggle_line_value.rs
+++ b/bindings/rust/libgpiod/examples/toggle_line_value.rs
@@ -5,9 +5,12 @@
use core::time::Duration;
use libgpiod::{
- line::{self, Value},
+ chip::Chip,
+ line::{Config as LineConfig, Direction, Settings, Value},
+ request::Config as ReqConfig,
Result,
};
+use std::thread::sleep;
fn toggle_value(value: Value) -> Value {
match value {
@@ -22,23 +25,23 @@ fn main() -> Result<()> {
let line_offset = 5;
let mut value = Value::Active;
- let mut settings = line::Settings::new()?;
+ let mut settings = Settings::new()?;
settings
- .set_direction(line::Direction::Output)?
+ .set_direction(Direction::Output)?
.set_output_value(value)?;
- let mut lconfig = line::Config::new()?;
+ let mut lconfig = LineConfig::new()?;
lconfig.add_line_settings(&[line_offset], settings)?;
- let mut rconfig = libgpiod::request::Config::new()?;
+ let mut rconfig = ReqConfig::new()?;
rconfig.set_consumer("toggle-line-value")?;
- let chip = libgpiod::chip::Chip::open(&chip_path)?;
+ let chip = Chip::open(&chip_path)?;
let mut req = chip.request_lines(Some(&rconfig), &lconfig)?;
loop {
println!("{line_offset}={value:?}");
- std::thread::sleep(Duration::from_secs(1));
+ sleep(Duration::from_secs(1));
value = toggle_value(value);
req.set_value(line_offset, value)?;
}
diff --git a/bindings/rust/libgpiod/examples/toggle_multiple_line_values.rs b/bindings/rust/libgpiod/examples/toggle_multiple_line_values.rs
index e15b09392ccbf38d99a1aa591c6022fab64f7ecf..3572deb19734146c4727e05a5273b6ec52fa14e8 100644
--- a/bindings/rust/libgpiod/examples/toggle_multiple_line_values.rs
+++ b/bindings/rust/libgpiod/examples/toggle_multiple_line_values.rs
@@ -5,9 +5,12 @@
use core::time::Duration;
use libgpiod::{
- line::{self, Offset, Value},
+ chip::Chip,
+ line::{Config as LineConfig, Direction, Offset, Settings, Value},
+ request::Config as ReqConfig,
Result,
};
+use std::thread::sleep;
fn toggle_value(value: Value) -> Value {
match value {
@@ -35,23 +38,23 @@ fn main() -> Result<()> {
let line_offsets = [5, 3, 7];
let mut values = vec![Value::Active, Value::Active, Value::InActive];
- let mut lsettings = line::Settings::new()?;
- lsettings.set_direction(line::Direction::Output)?;
+ let mut lsettings = Settings::new()?;
+ lsettings.set_direction(Direction::Output)?;
- let mut lconfig = line::Config::new()?;
+ let mut lconfig = LineConfig::new()?;
lconfig
.add_line_settings(&line_offsets, lsettings)?
.set_output_values(&values)?;
- let mut rconfig = libgpiod::request::Config::new()?;
+ let mut rconfig = ReqConfig::new()?;
rconfig.set_consumer("toggle-multiple-line-values")?;
- let chip = libgpiod::chip::Chip::open(&chip_path)?;
+ let chip = Chip::open(&chip_path)?;
let mut req = chip.request_lines(Some(&rconfig), &lconfig)?;
loop {
print_values(&line_offsets, &values);
- std::thread::sleep(Duration::from_secs(1));
+ sleep(Duration::from_secs(1));
toggle_values(&mut values);
req.set_values(&values)?;
}
diff --git a/bindings/rust/libgpiod/examples/watch_line_rising.rs b/bindings/rust/libgpiod/examples/watch_line_rising.rs
index 00e65f0e9df3cf73613f71173bcc8c1f6beb5ae5..77434ae89d3ca76e1686d6debddd88141a3dda08 100644
--- a/bindings/rust/libgpiod/examples/watch_line_rising.rs
+++ b/bindings/rust/libgpiod/examples/watch_line_rising.rs
@@ -3,28 +3,33 @@
//
// Minimal example of watching for edges on a single line.
-use libgpiod::{line, Result};
+use libgpiod::{
+ chip::Chip,
+ line::{Config as LineConfig, Edge, EdgeKind, Settings},
+ request::{Buffer, Config as ReqConfig},
+ Result,
+};
fn main() -> Result<()> {
// Example configuration - customize to suit your situation
let chip_path = "/dev/gpiochip0";
let line_offset = 5;
- let mut lsettings = line::Settings::new()?;
- lsettings.set_edge_detection(Some(line::Edge::Rising))?;
+ let mut lsettings = Settings::new()?;
+ lsettings.set_edge_detection(Some(Edge::Rising))?;
- let mut lconfig = line::Config::new()?;
+ let mut lconfig = LineConfig::new()?;
lconfig.add_line_settings(&[line_offset], lsettings)?;
- let mut rconfig = libgpiod::request::Config::new()?;
+ let mut rconfig = ReqConfig::new()?;
rconfig.set_consumer("watch-line-value")?;
- let chip = libgpiod::chip::Chip::open(&chip_path)?;
+ let chip = Chip::open(&chip_path)?;
let request = chip.request_lines(Some(&rconfig), &lconfig)?;
// A larger buffer is an optimisation for reading bursts of events from the
// kernel, but that is not necessary in this case, so 1 is fine.
- let mut buffer = libgpiod::request::Buffer::new(1)?;
+ let mut buffer = Buffer::new(1)?;
loop {
// blocks until at least one event is available
let events = request.read_edge_events(&mut buffer)?;
@@ -34,8 +39,8 @@ fn main() -> Result<()> {
"line: {} type: {:<7} event #{}",
event.line_offset(),
match event.event_type()? {
- line::EdgeKind::Rising => "Rising",
- line::EdgeKind::Falling => "Falling",
+ EdgeKind::Rising => "Rising",
+ EdgeKind::Falling => "Falling",
},
event.line_seqno()
);
diff --git a/bindings/rust/libgpiod/examples/watch_line_value.rs b/bindings/rust/libgpiod/examples/watch_line_value.rs
index 3df5a2bec2910a96d36da989b34624e2f669394c..3d5bc86724e316077bfb24b8fbf4f2365bb429ab 100644
--- a/bindings/rust/libgpiod/examples/watch_line_value.rs
+++ b/bindings/rust/libgpiod/examples/watch_line_value.rs
@@ -3,7 +3,12 @@
//
// Minimal example of watching for edges on a single line.
-use libgpiod::{line, Result};
+use libgpiod::{
+ chip::Chip,
+ line::{Bias, Config as LineConfig, Edge, EdgeKind, Settings},
+ request::{Buffer, Config as ReqConfig},
+ Result,
+};
use std::time::Duration;
fn main() -> Result<()> {
@@ -11,26 +16,26 @@ fn main() -> Result<()> {
let chip_path = "/dev/gpiochip0";
let line_offset = 5;
- let mut lsettings = line::Settings::new()?;
+ let mut lsettings = Settings::new()?;
// Assume a button connecting the pin to ground,
// so pull it up and provide some debounce.
lsettings
- .set_edge_detection(Some(line::Edge::Both))?
- .set_bias(Some(line::Bias::PullUp))?
+ .set_edge_detection(Some(Edge::Both))?
+ .set_bias(Some(Bias::PullUp))?
.set_debounce_period(Duration::from_millis(10));
- let mut lconfig = line::Config::new()?;
+ let mut lconfig = LineConfig::new()?;
lconfig.add_line_settings(&[line_offset], lsettings)?;
- let mut rconfig = libgpiod::request::Config::new()?;
+ let mut rconfig = ReqConfig::new()?;
rconfig.set_consumer("watch-line-value")?;
- let chip = libgpiod::chip::Chip::open(&chip_path)?;
+ let chip = Chip::open(&chip_path)?;
let request = chip.request_lines(Some(&rconfig), &lconfig)?;
// A larger buffer is an optimisation for reading bursts of events from the
// kernel, but that is not necessary in this case, so 1 is fine.
- let mut buffer = libgpiod::request::Buffer::new(1)?;
+ let mut buffer = Buffer::new(1)?;
loop {
// blocks until at least one event is available
let events = request.read_edge_events(&mut buffer)?;
@@ -40,8 +45,8 @@ fn main() -> Result<()> {
"line: {} type: {:<7} event #{}",
event.line_offset(),
match event.event_type()? {
- line::EdgeKind::Rising => "Rising",
- line::EdgeKind::Falling => "Falling",
+ EdgeKind::Rising => "Rising",
+ EdgeKind::Falling => "Falling",
},
event.line_seqno()
);
diff --git a/bindings/rust/libgpiod/examples/watch_multiple_line_values.rs b/bindings/rust/libgpiod/examples/watch_multiple_line_values.rs
index 81d211784d4929eb925231d05199a61a24816d74..10079ac8cc0da733adeadefd101455c046eaa7fd 100644
--- a/bindings/rust/libgpiod/examples/watch_multiple_line_values.rs
+++ b/bindings/rust/libgpiod/examples/watch_multiple_line_values.rs
@@ -4,8 +4,10 @@
// Minimal example of watching for edges on multiple lines.
use libgpiod::{
- line::{self, EdgeKind},
- request, Result,
+ chip::Chip,
+ line::{Config as LineConfig, Edge, EdgeKind, Settings},
+ request::{Buffer, Config as ReqConfig},
+ Result,
};
fn main() -> Result<()> {
@@ -13,19 +15,19 @@ fn main() -> Result<()> {
let chip_path = "/dev/gpiochip0";
let line_offsets = [5, 3, 7];
- let mut lsettings = line::Settings::new()?;
- lsettings.set_edge_detection(Some(line::Edge::Both))?;
+ let mut lsettings = Settings::new()?;
+ lsettings.set_edge_detection(Some(Edge::Both))?;
- let mut lconfig = line::Config::new()?;
+ let mut lconfig = LineConfig::new()?;
lconfig.add_line_settings(&line_offsets, lsettings)?;
- let mut rconfig = request::Config::new()?;
+ let mut rconfig = ReqConfig::new()?;
rconfig.set_consumer("watch-multiple-line-values")?;
- let chip = libgpiod::chip::Chip::open(&chip_path)?;
+ let chip = Chip::open(&chip_path)?;
let request = chip.request_lines(Some(&rconfig), &lconfig)?;
- let mut buffer = request::Buffer::new(4)?;
+ let mut buffer = Buffer::new(4)?;
loop {
// Blocks until at least one event is available.
let events = request.read_edge_events(&mut buffer)?;
--
2.48.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH libgpiod 2/3] bindings: rust: update formatting to --edition 2024
2025-09-26 14:35 [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks Bartosz Golaszewski
2025-09-26 14:35 ` [PATCH libgpiod 1/3] bindings: rust: complete the unification of exports in examples Bartosz Golaszewski
@ 2025-09-26 14:35 ` Bartosz Golaszewski
2025-09-26 14:35 ` [PATCH libgpiod 3/3] bindings: rust: add examples to the README.md in the libgpiod crate Bartosz Golaszewski
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Bartosz Golaszewski @ 2025-09-26 14:35 UTC (permalink / raw)
To: Erik Wierich, Viresh Kumar, Linus Walleij; +Cc: linux-gpio, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Update the formatting of all rust source files to be up to date with the
2024 rust edition.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
bindings/rust/gpiosim-sys/src/lib.rs | 2 +-
bindings/rust/gpiosim-sys/src/sim.rs | 2 +-
.../libgpiod/examples/buffered_event_lifetimes.rs | 2 +-
.../rust/libgpiod/examples/find_line_by_name.rs | 2 +-
bindings/rust/libgpiod/examples/get_chip_info.rs | 2 +-
bindings/rust/libgpiod/examples/get_line_info.rs | 2 +-
bindings/rust/libgpiod/examples/get_line_value.rs | 2 +-
.../libgpiod/examples/get_multiple_line_values.rs | 2 +-
.../examples/reconfigure_input_to_output.rs | 2 +-
.../rust/libgpiod/examples/toggle_line_value.rs | 2 +-
.../examples/toggle_multiple_line_values.rs | 2 +-
bindings/rust/libgpiod/examples/watch_line_info.rs | 2 +-
.../rust/libgpiod/examples/watch_line_rising.rs | 2 +-
.../rust/libgpiod/examples/watch_line_value.rs | 2 +-
.../examples/watch_multiple_line_values.rs | 2 +-
bindings/rust/libgpiod/src/chip.rs | 4 +-
bindings/rust/libgpiod/src/edge_event.rs | 3 +-
bindings/rust/libgpiod/src/event_buffer.rs | 3 +-
bindings/rust/libgpiod/src/info_event.rs | 3 +-
bindings/rust/libgpiod/src/lib.rs | 2 +-
bindings/rust/libgpiod/src/line_config.rs | 3 +-
bindings/rust/libgpiod/src/line_info.rs | 3 +-
bindings/rust/libgpiod/src/line_request.rs | 4 +-
bindings/rust/libgpiod/src/line_settings.rs | 3 +-
bindings/rust/libgpiod/src/request_config.rs | 2 +-
bindings/rust/libgpiod/tests/chip.rs | 2 +-
bindings/rust/libgpiod/tests/common/config.rs | 3 +-
bindings/rust/libgpiod/tests/edge_event.rs | 120 ++++++++++++---------
bindings/rust/libgpiod/tests/info_event.rs | 58 +++++-----
bindings/rust/libgpiod/tests/line_info.rs | 2 +-
bindings/rust/libgpiod/tests/line_request.rs | 12 ++-
bindings/rust/libgpiod/tests/request_config.rs | 2 +-
32 files changed, 144 insertions(+), 115 deletions(-)
diff --git a/bindings/rust/gpiosim-sys/src/lib.rs b/bindings/rust/gpiosim-sys/src/lib.rs
index bf9ae32eda0cf7220e70975e2dfa4c093f46ce90..e03c8e3eabee427f287a389b3425a123689324d6 100644
--- a/bindings/rust/gpiosim-sys/src/lib.rs
+++ b/bindings/rust/gpiosim-sys/src/lib.rs
@@ -44,7 +44,7 @@ impl Value {
return Err(Error::OperationFailed(
OperationType::SimBankGetVal,
errno::errno(),
- ))
+ ));
}
_ => return Err(Error::InvalidEnumValue("Value", val)),
})
diff --git a/bindings/rust/gpiosim-sys/src/sim.rs b/bindings/rust/gpiosim-sys/src/sim.rs
index 85c24948d247c71ffcb364db82473ca43ee2aca9..38ee73a1277c9af37a33995fff35916e50dcfa76 100644
--- a/bindings/rust/gpiosim-sys/src/sim.rs
+++ b/bindings/rust/gpiosim-sys/src/sim.rs
@@ -7,7 +7,7 @@ use std::os::raw::c_char;
use std::path::PathBuf;
use std::str;
-use libgpiod::{line::Offset, Error, OperationType, Result};
+use libgpiod::{Error, OperationType, Result, line::Offset};
use crate::*;
diff --git a/bindings/rust/libgpiod/examples/buffered_event_lifetimes.rs b/bindings/rust/libgpiod/examples/buffered_event_lifetimes.rs
index 7589e1f4187d364f28477c0d410b7e666608ac88..2fc3f08ab9d2bec734b13d8915182f5ebd31b8e1 100644
--- a/bindings/rust/libgpiod/examples/buffered_event_lifetimes.rs
+++ b/bindings/rust/libgpiod/examples/buffered_event_lifetimes.rs
@@ -6,10 +6,10 @@
// subsequent writes to the containing event buffer.
use libgpiod::{
+ Result,
chip::Chip,
line::{Config as LineConfig, Edge, Settings},
request::{Buffer, Config as ReqConfig, Event},
- Result,
};
fn main() -> Result<()> {
diff --git a/bindings/rust/libgpiod/examples/find_line_by_name.rs b/bindings/rust/libgpiod/examples/find_line_by_name.rs
index 3652b6419731b7e85d594906a1b5d41eed63fcb6..ddb264c861d9cf93027086367b8f96676fddda4f 100644
--- a/bindings/rust/libgpiod/examples/find_line_by_name.rs
+++ b/bindings/rust/libgpiod/examples/find_line_by_name.rs
@@ -3,7 +3,7 @@
//
// Minimal example of finding a line with the given name.
-use libgpiod::{gpiochip_devices, Result};
+use libgpiod::{Result, gpiochip_devices};
fn main() -> Result<()> {
// Example configuration - customize to suit your situation
diff --git a/bindings/rust/libgpiod/examples/get_chip_info.rs b/bindings/rust/libgpiod/examples/get_chip_info.rs
index 1781d464f0e66471ac1beb038d566eb537fed402..d5d57f863651b3643d75745abdf8e1efad0e342d 100644
--- a/bindings/rust/libgpiod/examples/get_chip_info.rs
+++ b/bindings/rust/libgpiod/examples/get_chip_info.rs
@@ -3,7 +3,7 @@
//
// Minimal example of reading the info for a chip.
-use libgpiod::{self, chip::Chip, Result};
+use libgpiod::{self, Result, chip::Chip};
fn main() -> Result<()> {
// Example configuration - customize to suit your situation
diff --git a/bindings/rust/libgpiod/examples/get_line_info.rs b/bindings/rust/libgpiod/examples/get_line_info.rs
index 36c6fbea4c873be473bbbd7d6b91c6925084c9d8..017f5187b6e2dd791c1d1277be01dae3a129a7d9 100644
--- a/bindings/rust/libgpiod/examples/get_line_info.rs
+++ b/bindings/rust/libgpiod/examples/get_line_info.rs
@@ -3,7 +3,7 @@
//
// Minimal example of reading the info for a line.
-use libgpiod::{chip::Chip, line::Direction, Result};
+use libgpiod::{Result, chip::Chip, line::Direction};
fn main() -> Result<()> {
// Example configuration - customize to suit your situation
diff --git a/bindings/rust/libgpiod/examples/get_line_value.rs b/bindings/rust/libgpiod/examples/get_line_value.rs
index 9986931af29a284131ce21fe11915285264786eb..844e30cda9671928c2041ff5a534100bdcab9d24 100644
--- a/bindings/rust/libgpiod/examples/get_line_value.rs
+++ b/bindings/rust/libgpiod/examples/get_line_value.rs
@@ -4,10 +4,10 @@
// Minimal example of reading a single line.
use libgpiod::{
+ Result,
chip::Chip,
line::{Config as LineConfig, Direction, Settings},
request::Config as ReqConfig,
- Result,
};
fn main() -> Result<()> {
diff --git a/bindings/rust/libgpiod/examples/get_multiple_line_values.rs b/bindings/rust/libgpiod/examples/get_multiple_line_values.rs
index a33a787fba4e94060c83a9c909b0f9c74517d7c1..39f0767cff9d62c73ef4f7f753c6de8fdfb45187 100644
--- a/bindings/rust/libgpiod/examples/get_multiple_line_values.rs
+++ b/bindings/rust/libgpiod/examples/get_multiple_line_values.rs
@@ -4,10 +4,10 @@
// Minimal example of reading multiple lines.
use libgpiod::{
+ Result,
chip::Chip,
line::{Config as LineConfig, Direction, Settings},
request::Config as ReqConfig,
- Result,
};
fn main() -> Result<()> {
diff --git a/bindings/rust/libgpiod/examples/reconfigure_input_to_output.rs b/bindings/rust/libgpiod/examples/reconfigure_input_to_output.rs
index ded576529212de4aaea0c025f7d1d38c44baaa7c..b82f19bb407459fed651d06ffc3e5ee3e81da7e3 100644
--- a/bindings/rust/libgpiod/examples/reconfigure_input_to_output.rs
+++ b/bindings/rust/libgpiod/examples/reconfigure_input_to_output.rs
@@ -4,10 +4,10 @@
// Example of a bi-directional line requested as input and then switched to output.
use libgpiod::{
+ Result,
chip::Chip,
line::{Config as LineConfig, Direction, Settings, Value},
request::Config as ReqConfig,
- Result,
};
fn main() -> Result<()> {
diff --git a/bindings/rust/libgpiod/examples/toggle_line_value.rs b/bindings/rust/libgpiod/examples/toggle_line_value.rs
index 33b17d5a36364f4a0e9e93c0f68570f764fc31a4..f38a7083bec810da4a44f0f89049640cca7bbb2b 100644
--- a/bindings/rust/libgpiod/examples/toggle_line_value.rs
+++ b/bindings/rust/libgpiod/examples/toggle_line_value.rs
@@ -5,10 +5,10 @@
use core::time::Duration;
use libgpiod::{
+ Result,
chip::Chip,
line::{Config as LineConfig, Direction, Settings, Value},
request::Config as ReqConfig,
- Result,
};
use std::thread::sleep;
diff --git a/bindings/rust/libgpiod/examples/toggle_multiple_line_values.rs b/bindings/rust/libgpiod/examples/toggle_multiple_line_values.rs
index 3572deb19734146c4727e05a5273b6ec52fa14e8..a69b3aa086c36b686be6304efaf8ded45a9bc71a 100644
--- a/bindings/rust/libgpiod/examples/toggle_multiple_line_values.rs
+++ b/bindings/rust/libgpiod/examples/toggle_multiple_line_values.rs
@@ -5,10 +5,10 @@
use core::time::Duration;
use libgpiod::{
+ Result,
chip::Chip,
line::{Config as LineConfig, Direction, Offset, Settings, Value},
request::Config as ReqConfig,
- Result,
};
use std::thread::sleep;
diff --git a/bindings/rust/libgpiod/examples/watch_line_info.rs b/bindings/rust/libgpiod/examples/watch_line_info.rs
index d724b6749fed19504ad13d8c3eb20aa351d00148..804ae681f4510794ed0930314a004ec19c7c7f18 100644
--- a/bindings/rust/libgpiod/examples/watch_line_info.rs
+++ b/bindings/rust/libgpiod/examples/watch_line_info.rs
@@ -3,7 +3,7 @@
//
// Minimal example of watching for info changes on particular lines.
-use libgpiod::{chip::Chip, line::InfoChangeKind, Result};
+use libgpiod::{Result, chip::Chip, line::InfoChangeKind};
fn main() -> Result<()> {
// Example configuration - customize to suit your situation
diff --git a/bindings/rust/libgpiod/examples/watch_line_rising.rs b/bindings/rust/libgpiod/examples/watch_line_rising.rs
index 77434ae89d3ca76e1686d6debddd88141a3dda08..b0260a4af4602f7deab5c27a5c7480f2ebbb7caa 100644
--- a/bindings/rust/libgpiod/examples/watch_line_rising.rs
+++ b/bindings/rust/libgpiod/examples/watch_line_rising.rs
@@ -4,10 +4,10 @@
// Minimal example of watching for edges on a single line.
use libgpiod::{
+ Result,
chip::Chip,
line::{Config as LineConfig, Edge, EdgeKind, Settings},
request::{Buffer, Config as ReqConfig},
- Result,
};
fn main() -> Result<()> {
diff --git a/bindings/rust/libgpiod/examples/watch_line_value.rs b/bindings/rust/libgpiod/examples/watch_line_value.rs
index 3d5bc86724e316077bfb24b8fbf4f2365bb429ab..f7469ddb3d5da1d24ecc76d19e48895737a5c691 100644
--- a/bindings/rust/libgpiod/examples/watch_line_value.rs
+++ b/bindings/rust/libgpiod/examples/watch_line_value.rs
@@ -4,10 +4,10 @@
// Minimal example of watching for edges on a single line.
use libgpiod::{
+ Result,
chip::Chip,
line::{Bias, Config as LineConfig, Edge, EdgeKind, Settings},
request::{Buffer, Config as ReqConfig},
- Result,
};
use std::time::Duration;
diff --git a/bindings/rust/libgpiod/examples/watch_multiple_line_values.rs b/bindings/rust/libgpiod/examples/watch_multiple_line_values.rs
index 10079ac8cc0da733adeadefd101455c046eaa7fd..c9d65e612ae1206f419f1d350cf30b0e93190987 100644
--- a/bindings/rust/libgpiod/examples/watch_multiple_line_values.rs
+++ b/bindings/rust/libgpiod/examples/watch_multiple_line_values.rs
@@ -4,10 +4,10 @@
// Minimal example of watching for edges on multiple lines.
use libgpiod::{
+ Result,
chip::Chip,
line::{Config as LineConfig, Edge, EdgeKind, Settings},
request::{Buffer, Config as ReqConfig},
- Result,
};
fn main() -> Result<()> {
diff --git a/bindings/rust/libgpiod/src/chip.rs b/bindings/rust/libgpiod/src/chip.rs
index df1cef3bdef5d2014e951437c9fe89c119bff48c..1e98cb28efe97d7cd97363a62cd5b2b346cf381a 100644
--- a/bindings/rust/libgpiod/src/chip.rs
+++ b/bindings/rust/libgpiod/src/chip.rs
@@ -16,9 +16,9 @@ use std::str;
use std::time::Duration;
use super::{
- gpiod,
+ Error, OperationType, Result, gpiod,
line::{self, Offset},
- request, Error, OperationType, Result,
+ request,
};
/// GPIO chip
diff --git a/bindings/rust/libgpiod/src/edge_event.rs b/bindings/rust/libgpiod/src/edge_event.rs
index 7f8f3773ef4005ac41b5aa2504340069f3adad5d..45caf9ead0afa72dc0d5ea2f4facabb15b4bef2a 100644
--- a/bindings/rust/libgpiod/src/edge_event.rs
+++ b/bindings/rust/libgpiod/src/edge_event.rs
@@ -5,9 +5,8 @@
use std::time::Duration;
use super::{
- gpiod,
+ Error, OperationType, Result, gpiod,
line::{EdgeKind, Offset},
- Error, OperationType, Result,
};
/// Line edge events handling
diff --git a/bindings/rust/libgpiod/src/event_buffer.rs b/bindings/rust/libgpiod/src/event_buffer.rs
index 059de1adabb858ba211446b27312c60429c6cc07..4f8ae63907b5886abd5ab581f677f7ad4cc2ce96 100644
--- a/bindings/rust/libgpiod/src/event_buffer.rs
+++ b/bindings/rust/libgpiod/src/event_buffer.rs
@@ -5,9 +5,8 @@
use std::ptr;
use super::{
- gpiod,
+ Error, OperationType, Result, gpiod,
request::{Event, Request},
- Error, OperationType, Result,
};
/// Line edge events
diff --git a/bindings/rust/libgpiod/src/info_event.rs b/bindings/rust/libgpiod/src/info_event.rs
index f23701ab43ce5c215bb5260cd608d8e46b927079..4338680e83a7f4065099190408d0b503bfad9575 100644
--- a/bindings/rust/libgpiod/src/info_event.rs
+++ b/bindings/rust/libgpiod/src/info_event.rs
@@ -5,9 +5,8 @@
use std::time::Duration;
use super::{
- gpiod,
+ Error, OperationType, Result, gpiod,
line::{self, InfoChangeKind},
- Error, OperationType, Result,
};
/// Line status watch events
diff --git a/bindings/rust/libgpiod/src/lib.rs b/bindings/rust/libgpiod/src/lib.rs
index 76a2c1b76f3cf365866797742011b780ee5795d8..aacc82e79dc77f9563d90adaf5fcffeb86ce690b 100644
--- a/bindings/rust/libgpiod/src/lib.rs
+++ b/bindings/rust/libgpiod/src/lib.rs
@@ -192,7 +192,7 @@ pub mod line {
return Err(Error::OperationFailed(
OperationType::LineRequestGetVal,
errno::errno(),
- ))
+ ));
}
_ => return Err(Error::InvalidEnumValue("Value", val)),
})
diff --git a/bindings/rust/libgpiod/src/line_config.rs b/bindings/rust/libgpiod/src/line_config.rs
index 5850b9da3cba0d75f475246592796c2c52570e8e..e78b77b4df2aa932a9e976db3529e71fd0ef2137 100644
--- a/bindings/rust/libgpiod/src/line_config.rs
+++ b/bindings/rust/libgpiod/src/line_config.rs
@@ -3,9 +3,8 @@
// SPDX-FileCopyrightText: 2022 Viresh Kumar <viresh.kumar@linaro.org>
use super::{
- gpiod,
+ Error, OperationType, Result, gpiod,
line::{Offset, Settings, SettingsMap, Value},
- Error, OperationType, Result,
};
/// Line configuration objects.
diff --git a/bindings/rust/libgpiod/src/line_info.rs b/bindings/rust/libgpiod/src/line_info.rs
index 8def1ab4e52962fffa6911976e64204c3d02df6f..fc7f47dce103e5728fab90079d02cb3004882634 100644
--- a/bindings/rust/libgpiod/src/line_info.rs
+++ b/bindings/rust/libgpiod/src/line_info.rs
@@ -8,9 +8,8 @@ use std::time::Duration;
use std::{ffi::CStr, marker::PhantomData};
use super::{
- gpiod,
+ Error, Result, gpiod,
line::{Bias, Direction, Drive, Edge, EventClock, Offset},
- Error, Result,
};
/// Line info reference
diff --git a/bindings/rust/libgpiod/src/line_request.rs b/bindings/rust/libgpiod/src/line_request.rs
index 48d8d1a3a6fb5110ef295971cf44bcc70ff68c58..723a2903cdcef91edee30d54a41745d6c65f4097 100644
--- a/bindings/rust/libgpiod/src/line_request.rs
+++ b/bindings/rust/libgpiod/src/line_request.rs
@@ -8,9 +8,9 @@ use std::os::unix::prelude::AsRawFd;
use std::time::Duration;
use super::{
- gpiod,
+ Error, OperationType, Result, gpiod,
line::{self, Offset, Value, ValueMap},
- request, Error, OperationType, Result,
+ request,
};
/// Line request operations
diff --git a/bindings/rust/libgpiod/src/line_settings.rs b/bindings/rust/libgpiod/src/line_settings.rs
index 9ab8ea7173c4f214e6d513434435a144424ecc74..ce2aa564b3fdd8b1533290ba001e60311a9fe9d2 100644
--- a/bindings/rust/libgpiod/src/line_settings.rs
+++ b/bindings/rust/libgpiod/src/line_settings.rs
@@ -5,9 +5,8 @@
use std::time::Duration;
use super::{
- gpiod,
+ Error, OperationType, Result, gpiod,
line::{Bias, Direction, Drive, Edge, EventClock, SettingKind, SettingVal, Value},
- Error, OperationType, Result,
};
/// Line settings objects.
diff --git a/bindings/rust/libgpiod/src/request_config.rs b/bindings/rust/libgpiod/src/request_config.rs
index 9b66cc9d25e3a291e913476721b8e0bbad1edd2f..1419bdeaa09247871890a84f681673234cfb0957 100644
--- a/bindings/rust/libgpiod/src/request_config.rs
+++ b/bindings/rust/libgpiod/src/request_config.rs
@@ -6,7 +6,7 @@ use std::ffi::{CStr, CString};
use std::os::raw::c_char;
use std::str;
-use super::{gpiod, Error, OperationType, Result};
+use super::{Error, OperationType, Result, gpiod};
/// Request configuration objects
///
diff --git a/bindings/rust/libgpiod/tests/chip.rs b/bindings/rust/libgpiod/tests/chip.rs
index 60b4ecc431fce15f69e20fbad1ed40df7280f172..1fbe2b7089dc0ce90eb259aff9a0771b0718fb67 100644
--- a/bindings/rust/libgpiod/tests/chip.rs
+++ b/bindings/rust/libgpiod/tests/chip.rs
@@ -9,7 +9,7 @@ mod chip {
use std::path::PathBuf;
use gpiosim_sys::Sim;
- use libgpiod::{chip::Chip, Error as ChipError, OperationType};
+ use libgpiod::{Error as ChipError, OperationType, chip::Chip};
mod open {
use super::*;
diff --git a/bindings/rust/libgpiod/tests/common/config.rs b/bindings/rust/libgpiod/tests/common/config.rs
index 7bb1f659a92831ba3585f4e06b8fe6031d2243dc..d876df7f91ca0b86a03dda10bead7f9285043c10 100644
--- a/bindings/rust/libgpiod/tests/common/config.rs
+++ b/bindings/rust/libgpiod/tests/common/config.rs
@@ -7,9 +7,10 @@ use std::time::Duration;
use gpiosim_sys::{Pull, Sim, Value as SimValue};
use libgpiod::{
+ Result,
chip::Chip,
line::{self, Bias, Direction, Drive, Edge, EventClock, Offset, SettingVal, Value},
- request, Result,
+ request,
};
pub(crate) struct TestConfig {
diff --git a/bindings/rust/libgpiod/tests/edge_event.rs b/bindings/rust/libgpiod/tests/edge_event.rs
index 03b7e7cb05f7564170a27ba1cef0cb3892e6945f..a592f1db94bd6f3f7d06003c4cd9b7878c5a3b33 100644
--- a/bindings/rust/libgpiod/tests/edge_event.rs
+++ b/bindings/rust/libgpiod/tests/edge_event.rs
@@ -87,10 +87,12 @@ mod edge_event {
trigger_falling_and_rising_edge(config.sim(), GPIO);
// Rising event
- assert!(config
- .request()
- .wait_edge_events(Some(Duration::from_secs(1)))
- .unwrap());
+ assert!(
+ config
+ .request()
+ .wait_edge_events(Some(Duration::from_secs(1)))
+ .unwrap()
+ );
let mut events = config.request().read_edge_events(&mut buf).unwrap();
assert_eq!(events.len(), 1);
@@ -101,10 +103,12 @@ mod edge_event {
assert_eq!(event.line_offset(), GPIO);
// Falling event
- assert!(config
- .request()
- .wait_edge_events(Some(Duration::from_secs(1)))
- .unwrap());
+ assert!(
+ config
+ .request()
+ .wait_edge_events(Some(Duration::from_secs(1)))
+ .unwrap()
+ );
let mut events = config.request().read_edge_events(&mut buf).unwrap();
assert_eq!(events.len(), 1);
@@ -115,10 +119,12 @@ mod edge_event {
assert_eq!(event.line_offset(), GPIO);
// No events available
- assert!(!config
- .request()
- .wait_edge_events(Some(Duration::from_millis(100)))
- .unwrap());
+ assert!(
+ !config
+ .request()
+ .wait_edge_events(Some(Duration::from_millis(100)))
+ .unwrap()
+ );
assert!(ts_falling > ts_rising);
}
@@ -136,10 +142,12 @@ mod edge_event {
trigger_falling_and_rising_edge(config.sim(), GPIO);
// Rising event
- assert!(config
- .request()
- .wait_edge_events(Some(Duration::from_secs(1)))
- .unwrap());
+ assert!(
+ config
+ .request()
+ .wait_edge_events(Some(Duration::from_secs(1)))
+ .unwrap()
+ );
let mut events = config.request().read_edge_events(&mut buf).unwrap();
assert_eq!(events.len(), 1);
@@ -149,10 +157,12 @@ mod edge_event {
assert_eq!(event.line_offset(), GPIO);
// No events available
- assert!(!config
- .request()
- .wait_edge_events(Some(Duration::from_millis(100)))
- .unwrap());
+ assert!(
+ !config
+ .request()
+ .wait_edge_events(Some(Duration::from_millis(100)))
+ .unwrap()
+ );
}
#[test]
@@ -168,10 +178,12 @@ mod edge_event {
trigger_falling_and_rising_edge(config.sim(), GPIO);
// Falling event
- assert!(config
- .request()
- .wait_edge_events(Some(Duration::from_secs(1)))
- .unwrap());
+ assert!(
+ config
+ .request()
+ .wait_edge_events(Some(Duration::from_secs(1)))
+ .unwrap()
+ );
let mut events = config.request().read_edge_events(&mut buf).unwrap();
assert_eq!(events.len(), 1);
@@ -181,10 +193,12 @@ mod edge_event {
assert_eq!(event.line_offset(), GPIO);
// No events available
- assert!(!config
- .request()
- .wait_edge_events(Some(Duration::from_millis(100)))
- .unwrap());
+ assert!(
+ !config
+ .request()
+ .wait_edge_events(Some(Duration::from_millis(100)))
+ .unwrap()
+ );
}
#[test]
@@ -200,10 +214,12 @@ mod edge_event {
// Rising event GPIO 0
let mut buf = request::Buffer::new(0).unwrap();
- assert!(config
- .request()
- .wait_edge_events(Some(Duration::from_secs(1)))
- .unwrap());
+ assert!(
+ config
+ .request()
+ .wait_edge_events(Some(Duration::from_secs(1)))
+ .unwrap()
+ );
let mut events = config.request().read_edge_events(&mut buf).unwrap();
assert_eq!(events.len(), 1);
@@ -215,10 +231,12 @@ mod edge_event {
assert_eq!(event.line_seqno(), 1);
// Rising event GPIO 1
- assert!(config
- .request()
- .wait_edge_events(Some(Duration::from_secs(1)))
- .unwrap());
+ assert!(
+ config
+ .request()
+ .wait_edge_events(Some(Duration::from_secs(1)))
+ .unwrap()
+ );
let mut events = config.request().read_edge_events(&mut buf).unwrap();
assert_eq!(events.len(), 1);
@@ -230,10 +248,12 @@ mod edge_event {
assert_eq!(event.line_seqno(), 1);
// No events available
- assert!(!config
- .request()
- .wait_edge_events(Some(Duration::from_millis(100)))
- .unwrap());
+ assert!(
+ !config
+ .request()
+ .wait_edge_events(Some(Duration::from_millis(100)))
+ .unwrap()
+ );
}
#[test]
@@ -249,10 +269,12 @@ mod edge_event {
trigger_multiple_events(config.sim(), GPIO);
// Read multiple events
- assert!(config
- .request()
- .wait_edge_events(Some(Duration::from_secs(1)))
- .unwrap());
+ assert!(
+ config
+ .request()
+ .wait_edge_events(Some(Duration::from_secs(1)))
+ .unwrap()
+ );
let events = config.request().read_edge_events(&mut buf).unwrap();
assert_eq!(events.len(), 3);
@@ -285,10 +307,12 @@ mod edge_event {
trigger_multiple_events(config.sim(), GPIO);
// Read multiple events
- assert!(config
- .request()
- .wait_edge_events(Some(Duration::from_secs(1)))
- .unwrap());
+ assert!(
+ config
+ .request()
+ .wait_edge_events(Some(Duration::from_secs(1)))
+ .unwrap()
+ );
let events = config.request().read_edge_events(&mut buf).unwrap();
assert_eq!(events.len(), 2);
diff --git a/bindings/rust/libgpiod/tests/info_event.rs b/bindings/rust/libgpiod/tests/info_event.rs
index c969af78238374110bfdb5536b4cab771d977c15..83e465b3a3ce0f256f90fd60d6ecf225e462c208 100644
--- a/bindings/rust/libgpiod/tests/info_event.rs
+++ b/bindings/rust/libgpiod/tests/info_event.rs
@@ -8,8 +8,8 @@ mod info_event {
use libc::EINVAL;
use std::{
sync::{
- mpsc::{self, Receiver, Sender},
Arc, Mutex,
+ mpsc::{self, Receiver, Sender},
},
thread,
time::Duration,
@@ -17,9 +17,10 @@ mod info_event {
use gpiosim_sys::Sim;
use libgpiod::{
+ Error as ChipError, OperationType,
chip::Chip,
line::{self, Direction, InfoChangeKind, Offset},
- request, Error as ChipError, OperationType,
+ request,
};
fn request_reconfigure_line(chip: Arc<Mutex<Chip>>, tx: Sender<()>, rx: Receiver<()>) {
@@ -75,9 +76,11 @@ mod info_event {
assert_eq!(info.offset(), GPIO);
// No events available
- assert!(!chip
- .wait_info_event(Some(Duration::from_millis(100)))
- .unwrap());
+ assert!(
+ !chip
+ .wait_info_event(Some(Duration::from_millis(100)))
+ .unwrap()
+ );
}
#[test]
@@ -99,11 +102,12 @@ mod info_event {
rx_main.recv().expect("Could not receive from channel");
// Line requested event
- assert!(chip
- .lock()
- .unwrap()
- .wait_info_event(Some(Duration::from_secs(1)))
- .unwrap());
+ assert!(
+ chip.lock()
+ .unwrap()
+ .wait_info_event(Some(Duration::from_secs(1)))
+ .unwrap()
+ );
let event = chip.lock().unwrap().read_info_event().unwrap();
let ts_req = event.timestamp();
@@ -120,11 +124,12 @@ mod info_event {
rx_main.recv().expect("Could not receive from channel");
// Line changed event
- assert!(chip
- .lock()
- .unwrap()
- .wait_info_event(Some(Duration::from_secs(1)))
- .unwrap());
+ assert!(
+ chip.lock()
+ .unwrap()
+ .wait_info_event(Some(Duration::from_secs(1)))
+ .unwrap()
+ );
let event = chip.lock().unwrap().read_info_event().unwrap();
let ts_rec = event.timestamp();
@@ -141,22 +146,25 @@ mod info_event {
tx_main.send(()).expect("Could not send signal on channel");
// Line released event
- assert!(chip
- .lock()
- .unwrap()
- .wait_info_event(Some(Duration::from_secs(1)))
- .unwrap());
+ assert!(
+ chip.lock()
+ .unwrap()
+ .wait_info_event(Some(Duration::from_secs(1)))
+ .unwrap()
+ );
let event = chip.lock().unwrap().read_info_event().unwrap();
let ts_rel = event.timestamp();
assert_eq!(event.event_type().unwrap(), InfoChangeKind::LineReleased);
// No events available
- assert!(!chip
- .lock()
- .unwrap()
- .wait_info_event(Some(Duration::from_millis(100)))
- .unwrap());
+ assert!(
+ !chip
+ .lock()
+ .unwrap()
+ .wait_info_event(Some(Duration::from_millis(100)))
+ .unwrap()
+ );
// Check timestamps are really monotonic.
assert!(ts_rel > ts_rec);
diff --git a/bindings/rust/libgpiod/tests/line_info.rs b/bindings/rust/libgpiod/tests/line_info.rs
index d02c9eaf576c5d7468ab90058c2cbe166cbdf641..85714eb7c65d0b319acca96c223d8d52b0f651e0 100644
--- a/bindings/rust/libgpiod/tests/line_info.rs
+++ b/bindings/rust/libgpiod/tests/line_info.rs
@@ -11,9 +11,9 @@ mod line_info {
use crate::common::*;
use gpiosim_sys::{Direction as SimDirection, Sim};
use libgpiod::{
+ Error as ChipError, OperationType,
chip::Chip,
line::{Bias, Direction, Drive, Edge, EventClock},
- Error as ChipError, OperationType,
};
const NGPIO: usize = 8;
diff --git a/bindings/rust/libgpiod/tests/line_request.rs b/bindings/rust/libgpiod/tests/line_request.rs
index 4ba0d18b0f635eeab4fba99a6bcf38db0bca9289..07b0987c6204b9b10ec71948438bc67b43ff97ee 100644
--- a/bindings/rust/libgpiod/tests/line_request.rs
+++ b/bindings/rust/libgpiod/tests/line_request.rs
@@ -11,10 +11,10 @@ mod line_request {
use crate::common::*;
use gpiosim_sys::{Pull, Value as SimValue};
use libgpiod::{
+ Error as ChipError, OperationType,
line::{
self, Bias, Direction, Drive, Edge, EventClock, Offset, SettingVal, Value, ValueMap,
},
- Error as ChipError, OperationType,
};
const NGPIO: usize = 8;
@@ -246,10 +246,12 @@ mod line_request {
config.request_lines().unwrap();
// No events available
- assert!(!config
- .request()
- .wait_edge_events(Some(Duration::from_millis(100)))
- .unwrap());
+ assert!(
+ !config
+ .request()
+ .wait_edge_events(Some(Duration::from_millis(100)))
+ .unwrap()
+ );
}
}
diff --git a/bindings/rust/libgpiod/tests/request_config.rs b/bindings/rust/libgpiod/tests/request_config.rs
index a925a6833105c85fc6016253ae449a4fe2e8da06..5eba3e179f5a73c3122a7d04b790cca0164a45cb 100644
--- a/bindings/rust/libgpiod/tests/request_config.rs
+++ b/bindings/rust/libgpiod/tests/request_config.rs
@@ -5,7 +5,7 @@
mod common;
mod request_config {
- use libgpiod::{request, Error as ChipError, OperationType};
+ use libgpiod::{Error as ChipError, OperationType, request};
mod verify {
use super::*;
--
2.48.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH libgpiod 3/3] bindings: rust: add examples to the README.md in the libgpiod crate
2025-09-26 14:35 [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks Bartosz Golaszewski
2025-09-26 14:35 ` [PATCH libgpiod 1/3] bindings: rust: complete the unification of exports in examples Bartosz Golaszewski
2025-09-26 14:35 ` [PATCH libgpiod 2/3] bindings: rust: update formatting to --edition 2024 Bartosz Golaszewski
@ 2025-09-26 14:35 ` Bartosz Golaszewski
2025-09-29 6:21 ` [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks Erik Schilling
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Bartosz Golaszewski @ 2025-09-26 14:35 UTC (permalink / raw)
To: Erik Wierich, Viresh Kumar, Linus Walleij; +Cc: linux-gpio, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Add some code examples to the README.md with the aim of showing how to
use the bindings on the crates.io landing page for the libgpiod crate.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
bindings/rust/libgpiod/README.md | 78 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
diff --git a/bindings/rust/libgpiod/README.md b/bindings/rust/libgpiod/README.md
index 1ef3743a99c967dca1be15f16bd3f299612bed16..0d764f472abf113d096a0e73b5d21f5790db9137 100644
--- a/bindings/rust/libgpiod/README.md
+++ b/bindings/rust/libgpiod/README.md
@@ -31,6 +31,84 @@ versions:
- `v2_1`: Minimum version of `2.1.x`
- `vnext`: The upcoming, still unreleased version of the C lib
+## Examples
+
+Get GPIO chip information:
+
+```rust
+let chip = Chip::open(&Path::new("/dev/gpiochip0"))?;
+let info = chip.info()?;
+
+println!("{} [{}] ({} lines)", info.name()?, info.label()?, info.num_lines());
+```
+
+Print GPIO line name:
+
+```rust
+let chip = Chip::open(&Path::new("/dev/gpiochip0"))?;
+let info = chip.line_info(0)?;
+let name = info.name().unwrap_or("unnamed");
+
+println!("{name}");
+```
+
+Toggle GPIO line output value:
+
+```rust
+let mut settings = line::Settings::new()?;
+settings
+ .set_direction(line::Direction::Output)?
+ .set_output_value(Value::Active)?;
+
+let mut line_cfg = line::Config::new()?;
+line_cfg.add_line_settings(&[line_offset], settings)?;
+
+let mut req_cfg = request::Config::new()?;
+req_cfg.set_consumer("toggle-line-value")?;
+
+let chip = Chip::open(&Path::new("/dev/gpiochip0"))?;
+
+/* Request with value 1 */
+let mut req = chip.request_lines(Some(&req_cfg), &line_cfg)?;
+
+/* Toggle to value 0 */
+req.set_value(line_offset, Value::InActive)?;
+```
+
+Read GPIO line event:
+
+```rust
+let mut lsettings = line::Settings::new()?;
+lsettings
+ .set_direction(line::Direction::Input)?
+ .set_edge_detection(Some(line::Edge::Both))?;
+
+let mut line_cfg = line::Config::new()?;
+line_cfg.add_line_settings(&[line_offset], settings)?;
+
+let mut req_cfg = request::Config::new()?;
+req_cfg.set_consumer("toggle-line-value")?;
+
+let chip = Chip::open(&Path::new("/dev/gpiochip0"))?;
+let req = chip.request_lines(Some(&req_cfg), &line_cfg)?;
+
+let mut buffer = request::Buffer::new(1)?;
+
+loop {
+ let events = req.read_edge_events(&mut buffer)?;
+ for event in events {
+ println!(
+ "line: {} type: {}",
+ event.line_offset(),
+ match event.event_type()? {
+ EdgeKind::Rising => "Rising",
+ EdgeKind::Falling => "Falling",
+ }
+ );
+ }
+}
+```
+
## License
This project is licensed under either of
--
2.48.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH libgpiod 1/3] bindings: rust: complete the unification of exports in examples
2025-09-26 14:35 ` [PATCH libgpiod 1/3] bindings: rust: complete the unification of exports in examples Bartosz Golaszewski
@ 2025-09-29 6:21 ` Erik Schilling
2025-09-29 7:29 ` Bartosz Golaszewski
0 siblings, 1 reply; 9+ messages in thread
From: Erik Schilling @ 2025-09-29 6:21 UTC (permalink / raw)
To: Bartosz Golaszewski, Viresh Kumar, Linus Walleij
Cc: linux-gpio, Bartosz Golaszewski
On Fri Sep 26, 2025 at 4:35 PM CEST, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> Commit cd32f27dd550 ("bindings: rust: unify imports in examples") failed
> to consistently unify the code across all examples so finish the
> process.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
> .../rust/libgpiod/examples/toggle_line_value.rs | 17 +++++++++------
> .../examples/toggle_multiple_line_values.rs | 17 +++++++++------
> .../rust/libgpiod/examples/watch_line_rising.rs | 23 ++++++++++++--------
> .../rust/libgpiod/examples/watch_line_value.rs | 25 +++++++++++++---------
> .../examples/watch_multiple_line_values.rs | 18 +++++++++-------
> 5 files changed, 59 insertions(+), 41 deletions(-)
nit: Was a bit confused by "complete unifications of exports". Shouldn't
this be "imports" (as used by the previous commit)?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks
2025-09-26 14:35 [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks Bartosz Golaszewski
` (2 preceding siblings ...)
2025-09-26 14:35 ` [PATCH libgpiod 3/3] bindings: rust: add examples to the README.md in the libgpiod crate Bartosz Golaszewski
@ 2025-09-29 6:21 ` Erik Schilling
2025-09-29 7:34 ` Viresh Kumar
2025-09-30 7:54 ` Bartosz Golaszewski
5 siblings, 0 replies; 9+ messages in thread
From: Erik Schilling @ 2025-09-29 6:21 UTC (permalink / raw)
To: Bartosz Golaszewski, Viresh Kumar, Linus Walleij
Cc: linux-gpio, Bartosz Golaszewski
On Fri Sep 26, 2025 at 4:35 PM CEST, Bartosz Golaszewski wrote:
> Here are some final tweaks before I do the 1.0.0 release of libgpiod
> rust crates. The first patch completes what I though I already did last
> time when updating the examples but I must have borked. The second patch
> just runs `rustfmt --edition 2024` on all source files. Finally the last
> patch adds some examples to the readme so that the landing page on
> crates.io already shows how to use the code.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
> Bartosz Golaszewski (3):
> bindings: rust: complete the unification of exports in examples
> bindings: rust: update formatting to --edition 2024
> bindings: rust: add examples to the README.md in the libgpiod crate
>
> bindings/rust/gpiosim-sys/src/lib.rs | 2 +-
> bindings/rust/gpiosim-sys/src/sim.rs | 2 +-
> bindings/rust/libgpiod/README.md | 78 ++++++++++++++
> .../libgpiod/examples/buffered_event_lifetimes.rs | 2 +-
> .../rust/libgpiod/examples/find_line_by_name.rs | 2 +-
> bindings/rust/libgpiod/examples/get_chip_info.rs | 2 +-
> bindings/rust/libgpiod/examples/get_line_info.rs | 2 +-
> bindings/rust/libgpiod/examples/get_line_value.rs | 2 +-
> .../libgpiod/examples/get_multiple_line_values.rs | 2 +-
> .../examples/reconfigure_input_to_output.rs | 2 +-
> .../rust/libgpiod/examples/toggle_line_value.rs | 17 +--
> .../examples/toggle_multiple_line_values.rs | 17 +--
> bindings/rust/libgpiod/examples/watch_line_info.rs | 2 +-
> .../rust/libgpiod/examples/watch_line_rising.rs | 23 ++--
> .../rust/libgpiod/examples/watch_line_value.rs | 25 +++--
> .../examples/watch_multiple_line_values.rs | 18 ++--
> bindings/rust/libgpiod/src/chip.rs | 4 +-
> bindings/rust/libgpiod/src/edge_event.rs | 3 +-
> bindings/rust/libgpiod/src/event_buffer.rs | 3 +-
> bindings/rust/libgpiod/src/info_event.rs | 3 +-
> bindings/rust/libgpiod/src/lib.rs | 2 +-
> bindings/rust/libgpiod/src/line_config.rs | 3 +-
> bindings/rust/libgpiod/src/line_info.rs | 3 +-
> bindings/rust/libgpiod/src/line_request.rs | 4 +-
> bindings/rust/libgpiod/src/line_settings.rs | 3 +-
> bindings/rust/libgpiod/src/request_config.rs | 2 +-
> bindings/rust/libgpiod/tests/chip.rs | 2 +-
> bindings/rust/libgpiod/tests/common/config.rs | 3 +-
> bindings/rust/libgpiod/tests/edge_event.rs | 120 ++++++++++++---------
> bindings/rust/libgpiod/tests/info_event.rs | 58 +++++-----
> bindings/rust/libgpiod/tests/line_info.rs | 2 +-
> bindings/rust/libgpiod/tests/line_request.rs | 12 ++-
> bindings/rust/libgpiod/tests/request_config.rs | 2 +-
> 33 files changed, 276 insertions(+), 151 deletions(-)
> ---
> base-commit: 97ee30872853b2c9fbb448240012909d985f2e19
> change-id: 20250925-rust-release-tweaks-d1a94bfda0c4
>
> Best regards,
> --
> Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Erik Wierich <erik@riscstar.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH libgpiod 1/3] bindings: rust: complete the unification of exports in examples
2025-09-29 6:21 ` Erik Schilling
@ 2025-09-29 7:29 ` Bartosz Golaszewski
0 siblings, 0 replies; 9+ messages in thread
From: Bartosz Golaszewski @ 2025-09-29 7:29 UTC (permalink / raw)
To: Erik Schilling
Cc: Viresh Kumar, Linus Walleij, linux-gpio, Bartosz Golaszewski
On Mon, Sep 29, 2025 at 8:21 AM Erik Schilling <erik@riscstar.com> wrote:
>
> On Fri Sep 26, 2025 at 4:35 PM CEST, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >
> > Commit cd32f27dd550 ("bindings: rust: unify imports in examples") failed
> > to consistently unify the code across all examples so finish the
> > process.
> >
> > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > ---
> > .../rust/libgpiod/examples/toggle_line_value.rs | 17 +++++++++------
> > .../examples/toggle_multiple_line_values.rs | 17 +++++++++------
> > .../rust/libgpiod/examples/watch_line_rising.rs | 23 ++++++++++++--------
> > .../rust/libgpiod/examples/watch_line_value.rs | 25 +++++++++++++---------
> > .../examples/watch_multiple_line_values.rs | 18 +++++++++-------
> > 5 files changed, 59 insertions(+), 41 deletions(-)
>
> nit: Was a bit confused by "complete unifications of exports". Shouldn't
> this be "imports" (as used by the previous commit)?
>
Ah, of course. I'll fix it when applying.
Bart
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks
2025-09-26 14:35 [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks Bartosz Golaszewski
` (3 preceding siblings ...)
2025-09-29 6:21 ` [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks Erik Schilling
@ 2025-09-29 7:34 ` Viresh Kumar
2025-09-30 7:54 ` Bartosz Golaszewski
5 siblings, 0 replies; 9+ messages in thread
From: Viresh Kumar @ 2025-09-29 7:34 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Erik Wierich, Linus Walleij, linux-gpio, Bartosz Golaszewski
On 26-09-25, 16:35, Bartosz Golaszewski wrote:
> Here are some final tweaks before I do the 1.0.0 release of libgpiod
> rust crates. The first patch completes what I though I already did last
> time when updating the examples but I must have borked. The second patch
> just runs `rustfmt --edition 2024` on all source files. Finally the last
> patch adds some examples to the readme so that the landing page on
> crates.io already shows how to use the code.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
> Bartosz Golaszewski (3):
> bindings: rust: complete the unification of exports in examples
> bindings: rust: update formatting to --edition 2024
> bindings: rust: add examples to the README.md in the libgpiod crate
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks
2025-09-26 14:35 [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks Bartosz Golaszewski
` (4 preceding siblings ...)
2025-09-29 7:34 ` Viresh Kumar
@ 2025-09-30 7:54 ` Bartosz Golaszewski
5 siblings, 0 replies; 9+ messages in thread
From: Bartosz Golaszewski @ 2025-09-30 7:54 UTC (permalink / raw)
To: Erik Wierich, Viresh Kumar, Linus Walleij, Bartosz Golaszewski
Cc: Bartosz Golaszewski, linux-gpio
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
On Fri, 26 Sep 2025 16:35:41 +0200, Bartosz Golaszewski wrote:
> Here are some final tweaks before I do the 1.0.0 release of libgpiod
> rust crates. The first patch completes what I though I already did last
> time when updating the examples but I must have borked. The second patch
> just runs `rustfmt --edition 2024` on all source files. Finally the last
> patch adds some examples to the readme so that the landing page on
> crates.io already shows how to use the code.
>
> [...]
Applied, thanks!
[1/3] bindings: rust: complete the unification of exports in examples
https://git.kernel.org/brgl/libgpiod/c/e5494942299014784203e6718dba6664cb514958
[2/3] bindings: rust: update formatting to --edition 2024
https://git.kernel.org/brgl/libgpiod/c/d0f1291f4137c7243f44b118ca6ecfe0cd4fd92d
[3/3] bindings: rust: add examples to the README.md in the libgpiod crate
https://git.kernel.org/brgl/libgpiod/c/2eab5e896f7dd8e6ec5bea5070b95f09a2fbbcbb
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-09-30 7:54 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-26 14:35 [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks Bartosz Golaszewski
2025-09-26 14:35 ` [PATCH libgpiod 1/3] bindings: rust: complete the unification of exports in examples Bartosz Golaszewski
2025-09-29 6:21 ` Erik Schilling
2025-09-29 7:29 ` Bartosz Golaszewski
2025-09-26 14:35 ` [PATCH libgpiod 2/3] bindings: rust: update formatting to --edition 2024 Bartosz Golaszewski
2025-09-26 14:35 ` [PATCH libgpiod 3/3] bindings: rust: add examples to the README.md in the libgpiod crate Bartosz Golaszewski
2025-09-29 6:21 ` [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks Erik Schilling
2025-09-29 7:34 ` Viresh Kumar
2025-09-30 7:54 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).