Skip to content

Commit 52d8bea

Browse files
committed
Fix clippy warnings
1 parent 76803d5 commit 52d8bea

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/lib.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,16 @@
2626
//! use std::thread::sleep;
2727
//! use std::time::Duration;
2828
//!
29-
//! fn main() {
30-
//! let my_led = Pin::new(127); // number depends on chip, etc.
31-
//! my_led.with_exported(|| {
32-
//! my_led.set_direction(Direction::Out).unwrap();
33-
//! loop {
34-
//! my_led.set_value(0).unwrap();
35-
//! sleep(Duration::from_millis(200));
36-
//! my_led.set_value(1).unwrap();
37-
//! sleep(Duration::from_millis(200));
38-
//! }
39-
//! }).unwrap();
40-
//! }
29+
//! let my_led = Pin::new(127); // number depends on chip, etc.
30+
//! my_led.with_exported(|| {
31+
//! my_led.set_direction(Direction::Out).unwrap();
32+
//! loop {
33+
//! my_led.set_value(0).unwrap();
34+
//! sleep(Duration::from_millis(200));
35+
//! my_led.set_value(1).unwrap();
36+
//! sleep(Duration::from_millis(200));
37+
//! }
38+
//! }).unwrap();
4139
//! ```
4240
4341
#![cfg_attr(feature = "async-tokio", allow(deprecated))]
@@ -247,7 +245,7 @@ impl Pin {
247245
/// This function will error out if the kernel does not support the GPIO
248246
/// sysfs interface (i.e. `/sys/class/gpio` does not exist).
249247
pub fn is_exported(&self) -> bool {
250-
fs::metadata(&format!("/sys/class/gpio/gpio{}", self.pin_num)).is_ok()
248+
fs::metadata(format!("/sys/class/gpio/gpio{}", self.pin_num)).is_ok()
251249
}
252250

253251
/// Export the GPIO
@@ -276,7 +274,7 @@ impl Pin {
276274
/// }
277275
/// ```
278276
pub fn export(&self) -> Result<()> {
279-
if fs::metadata(&format!("/sys/class/gpio/gpio{}", self.pin_num)).is_err() {
277+
if fs::metadata(format!("/sys/class/gpio/gpio{}", self.pin_num)).is_err() {
280278
let mut export_file = File::create("/sys/class/gpio/export")?;
281279
export_file.write_all(format!("{}", self.pin_num).as_bytes())?;
282280
}
@@ -290,7 +288,7 @@ impl Pin {
290288
/// exported, it will return without error. That is, whenever
291289
/// this function returns Ok, the GPIO is not exported.
292290
pub fn unexport(&self) -> Result<()> {
293-
if fs::metadata(&format!("/sys/class/gpio/gpio{}", self.pin_num)).is_ok() {
291+
if fs::metadata(format!("/sys/class/gpio/gpio{}", self.pin_num)).is_ok() {
294292
let mut unexport_file = File::create("/sys/class/gpio/unexport")?;
295293
unexport_file.write_all(format!("{}", self.pin_num).as_bytes())?;
296294
}
@@ -501,15 +499,15 @@ impl Pin {
501499

502500
#[test]
503501
fn extract_pin_fom_path_test() {
504-
let tok1 = Pin::extract_pin_from_path(&"/sys/class/gpio/gpio951");
502+
let tok1 = Pin::extract_pin_from_path("/sys/class/gpio/gpio951");
505503
assert_eq!(951, tok1.unwrap());
506-
let tok2 = Pin::extract_pin_from_path(&"/sys/CLASS/gpio/gpio951/");
504+
let tok2 = Pin::extract_pin_from_path("/sys/CLASS/gpio/gpio951/");
507505
assert_eq!(951, tok2.unwrap());
508-
let tok3 = Pin::extract_pin_from_path(&"../../devices/soc0/gpiochip3/gpio/gpio124");
506+
let tok3 = Pin::extract_pin_from_path("../../devices/soc0/gpiochip3/gpio/gpio124");
509507
assert_eq!(124, tok3.unwrap());
510-
let err1 = Pin::extract_pin_from_path(&"/sys/CLASS/gpio/gpio");
508+
let err1 = Pin::extract_pin_from_path("/sys/CLASS/gpio/gpio");
511509
assert!(err1.is_err());
512-
let err2 = Pin::extract_pin_from_path(&"/sys/class/gpio/gpioSDS");
510+
let err2 = Pin::extract_pin_from_path("/sys/class/gpio/gpioSDS");
513511
assert!(err2.is_err());
514512
}
515513
#[cfg(not(target_os = "wasi"))]
@@ -532,7 +530,7 @@ impl PinPoller {
532530
/// Create a new PinPoller for the provided pin number
533531
#[cfg(any(target_os = "linux", target_os = "android"))]
534532
pub fn new(pin_num: u64) -> Result<PinPoller> {
535-
let devfile: File = File::open(&format!("/sys/class/gpio/gpio{}/value", pin_num))?;
533+
let devfile: File = File::open(format!("/sys/class/gpio/gpio{}/value", pin_num))?;
536534
let devfile_fd = devfile.as_raw_fd();
537535
let epoll_fd = epoll_create()?;
538536
let mut event = EpollEvent::new(EpollFlags::EPOLLPRI | EpollFlags::EPOLLET, 0u64);
@@ -609,7 +607,7 @@ pub struct AsyncPinPoller {
609607
#[cfg(feature = "mio-evented")]
610608
impl AsyncPinPoller {
611609
fn new(pin_num: u64) -> Result<Self> {
612-
let devfile = File::open(&format!("/sys/class/gpio/gpio{}/value", pin_num))?;
610+
let devfile = File::open(format!("/sys/class/gpio/gpio{}/value", pin_num))?;
613611
Ok(AsyncPinPoller { devfile })
614612
}
615613
}

0 commit comments

Comments
 (0)