linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Erik Wierich <erik@riscstar.com>,
	 Viresh Kumar <viresh.kumar@linaro.org>,
	 Linus Walleij <linus.walleij@linaro.org>
Cc: linux-gpio@vger.kernel.org,
	 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: [PATCH libgpiod 1/3] bindings: rust: complete the unification of exports in examples
Date: Fri, 26 Sep 2025 16:35:42 +0200	[thread overview]
Message-ID: <20250926-rust-release-tweaks-v1-1-beae932eb691@linaro.org> (raw)
In-Reply-To: <20250926-rust-release-tweaks-v1-0-beae932eb691@linaro.org>

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


  reply	other threads:[~2025-09-26 14:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-26 14:35 [PATCH libgpiod 0/3] bindings: rust: pre-release tweaks Bartosz Golaszewski
2025-09-26 14:35 ` Bartosz Golaszewski [this message]
2025-09-29  6:21   ` [PATCH libgpiod 1/3] bindings: rust: complete the unification of exports in examples 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250926-rust-release-tweaks-v1-1-beae932eb691@linaro.org \
    --to=brgl@bgdev.pl \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=erik@riscstar.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).