Skip to content

Commit 3b325b0

Browse files
committed
rustfmt: run cargo fmt on codebase
Signed-off-by: Paul Osborne <osbpau@gmail.com>
1 parent 36f1de3 commit 3b325b0

14 files changed

+112
-118
lines changed

src/commands/gpio_export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use options::GpioExportOptions;
109
use config::GpioConfig;
11-
use std::process::exit;
1210
use export;
11+
use options::GpioExportOptions;
12+
use std::process::exit;
1313

1414
pub fn main(config: &GpioConfig, opts: &GpioExportOptions) {
1515
let pin = match config.get_pin(opts.pin) {

src/commands/gpio_exportall.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use options::GpioExportAllOptions;
109
use config::GpioConfig;
11-
use std::process::exit;
1210
use export;
11+
use options::GpioExportAllOptions;
12+
use std::process::exit;
1313

1414
pub fn main(config: &GpioConfig, opts: &GpioExportAllOptions) {
1515
let symlink_root = match opts.symlink_root {

src/commands/gpio_poll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use options::GpioPollOptions;
109
use config::GpioConfig;
11-
use sysfs_gpio::Edge;
10+
use options::GpioPollOptions;
1211
use std::process::exit;
12+
use sysfs_gpio::Edge;
1313

1414
pub fn main(config: &GpioConfig, opts: &GpioPollOptions) {
1515
let timeout = opts.timeout.unwrap_or(-1);

src/commands/gpio_read.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use options::GpioReadOptions;
109
use config::GpioConfig;
10+
use options::GpioReadOptions;
1111
use std::process::exit;
1212

1313
pub fn main(config: &GpioConfig, opts: &GpioReadOptions) {

src/commands/gpio_status.rs

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use options::GpioStatusOptions;
109
use config::GpioConfig;
1110
use config::PinConfig;
12-
use sysfs_gpio::Direction;
11+
use options::GpioStatusOptions;
1312
use std::process::exit;
13+
use sysfs_gpio::Direction;
1414

1515
pub fn main(config: &GpioConfig, opts: &GpioStatusOptions) {
1616
match opts.pin {
@@ -34,32 +34,20 @@ pub fn main(config: &GpioConfig, opts: &GpioStatusOptions) {
3434
}
3535
}
3636

37-
3837
fn print_pin_header() {
39-
println!("| {:<10} | {:<10} | {:<10} | {:<10} | {:<10} | {:<10} |",
40-
"Number",
41-
"Exported",
42-
"Direction",
43-
"Active Low",
44-
"Names",
45-
"Value");
38+
println!(
39+
"| {:<10} | {:<10} | {:<10} | {:<10} | {:<10} | {:<10} |",
40+
"Number", "Exported", "Direction", "Active Low", "Names", "Value"
41+
);
4642
print_row_sep(false);
4743
}
4844

4945
fn print_row_sep(is_last: bool) {
50-
let col_sep = if is_last {
51-
"-"
52-
} else {
53-
"+"
54-
};
55-
println!("{}{:->13}{:->13}{:->13}{:->13}{:->13}{:->13}",
56-
col_sep,
57-
col_sep,
58-
col_sep,
59-
col_sep,
60-
col_sep,
61-
col_sep,
62-
col_sep);
46+
let col_sep = if is_last { "-" } else { "+" };
47+
println!(
48+
"{}{:->13}{:->13}{:->13}{:->13}{:->13}{:->13}",
49+
col_sep, col_sep, col_sep, col_sep, col_sep, col_sep, col_sep
50+
);
6351
}
6452

6553
fn print_pin_row(pin_config: &PinConfig, is_last: bool) {
@@ -80,22 +68,15 @@ fn print_pin_row(pin_config: &PinConfig, is_last: bool) {
8068

8169
for (pos, name) in pin_config.names.iter().enumerate() {
8270
if pos == 0 {
83-
println!("| {:<10} | {:<10} | {:<10} | {:<10} | {:<10} | {:<10} |",
84-
pin_config.num,
85-
pin_config.export,
86-
direction,
87-
pin_config.active_low,
88-
name,
89-
value);
71+
println!(
72+
"| {:<10} | {:<10} | {:<10} | {:<10} | {:<10} | {:<10} |",
73+
pin_config.num, pin_config.export, direction, pin_config.active_low, name, value
74+
);
9075
} else {
91-
println!("| {:<10} | {:<10} | {:<10} | {:<10} | {:<10} | {:<10} |",
92-
"",
93-
"",
94-
"",
95-
"",
96-
name,
97-
"");
98-
76+
println!(
77+
"| {:<10} | {:<10} | {:<10} | {:<10} | {:<10} | {:<10} |",
78+
"", "", "", "", name, ""
79+
);
9980
}
10081
}
10182
print_row_sep(is_last);

src/commands/gpio_unexport.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use options::GpioUnexportOptions;
109
use config::GpioConfig;
11-
use std::process::exit;
1210
use export;
11+
use options::GpioUnexportOptions;
12+
use std::process::exit;
1313

1414
pub fn main(config: &GpioConfig, opts: &GpioUnexportOptions) {
1515
let pin_config = config.get_pin(opts.pin).unwrap_or_else(|| {

src/commands/gpio_unexportall.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use options::GpioUnexportAllOptions;
109
use config::GpioConfig;
11-
use std::process::exit;
1210
use export;
11+
use options::GpioUnexportAllOptions;
12+
use std::process::exit;
1313

1414
pub fn main(config: &GpioConfig, opts: &GpioUnexportAllOptions) {
1515
let symlink_root = match opts.symlink_root {

src/commands/gpio_write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use options::GpioWriteOptions;
109
use config::GpioConfig;
10+
use options::GpioWriteOptions;
1111
use std::process::exit;
1212
use sysfs_gpio::Direction;
1313

src/commands/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
pub mod gpio_read;
109
pub mod gpio_export;
1110
pub mod gpio_exportall;
12-
pub mod gpio_write;
13-
pub mod gpio_unexport;
14-
pub mod gpio_unexportall;
1511
pub mod gpio_poll;
12+
pub mod gpio_read;
1613
pub mod gpio_status;
14+
pub mod gpio_unexport;
15+
pub mod gpio_unexportall;
16+
pub mod gpio_write;

src/config.rs

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// except according to those terms.
88

99
use glob::glob;
10-
use std::collections::{HashMap, BTreeSet};
10+
use std::collections::{BTreeSet, HashMap};
1111
use std::fmt;
1212
use std::fs::{self, File};
1313
use std::io;
@@ -58,11 +58,11 @@ pub struct PinConfig {
5858
pub mode: Option<u32>,
5959
}
6060

61-
fn default_direction()-> sysfs_gpio::Direction {
61+
fn default_direction() -> sysfs_gpio::Direction {
6262
sysfs_gpio::Direction::In
6363
}
6464

65-
fn bool_true()-> bool {
65+
fn bool_true() -> bool {
6666
true
6767
}
6868

@@ -120,10 +120,8 @@ impl FromStr for GpioConfig {
120120
let val_config: GpioConfig = toml::from_str(&config).unwrap();
121121
(val_config.validate().or_else(|e| Err(Error::from(e))))?;
122122
Ok(cfg)
123-
},
124-
Err(e) => {
125-
Err(Error::ParserErrors(e))
126-
},
123+
}
124+
Err(e) => Err(Error::ParserErrors(e)),
127125
}
128126
}
129127
}
@@ -138,11 +136,11 @@ impl GpioConfig {
138136
for pin in &self.pins {
139137
for name in &pin.names {
140138
if let Some(other_pin) = all_names.get(&name[..]) {
141-
return Err(Error::DuplicateNames(format!("Pins {} and {} share duplicate \
142-
name '{}'",
143-
pin.num,
144-
other_pin.num,
145-
name)));
139+
return Err(Error::DuplicateNames(format!(
140+
"Pins {} and {} share duplicate \
141+
name '{}'",
142+
pin.num, other_pin.num, name
143+
)));
146144
}
147145
all_names.insert(&name[..], pin);
148146
}
@@ -266,10 +264,10 @@ impl GpioConfig {
266264
#[cfg(test)]
267265
mod test {
268266
use super::*;
269-
use std::iter::FromIterator;
270267
use std::collections::BTreeSet;
271-
use sysfs_gpio::Direction as D;
268+
use std::iter::FromIterator;
272269
use std::str::FromStr;
270+
use sysfs_gpio::Direction as D;
273271

274272
const BASIC_CFG: &'static str = r#"
275273
[[pins]]
@@ -335,16 +333,20 @@ names = ["wildcard"]
335333
fn test_parse_basic() {
336334
let config = GpioConfig::from_str(BASIC_CFG).unwrap();
337335
let status_led = config.pins.get(1).unwrap();
338-
let names = BTreeSet::from_iter(vec![String::from("status_led"),
339-
String::from("A27"),
340-
String::from("green_led")]);
336+
let names = BTreeSet::from_iter(vec![
337+
String::from("status_led"),
338+
String::from("A27"),
339+
String::from("green_led"),
340+
]);
341341

342342
assert_eq!(config.get_symlink_root(), "/var/run/gpio");
343343

344344
let reset_button = config.pins.get(0).unwrap();
345345
assert_eq!(reset_button.num, 73);
346-
assert_eq!(reset_button.names,
347-
BTreeSet::from_iter(vec![String::from("reset_button")]));
346+
assert_eq!(
347+
reset_button.names,
348+
BTreeSet::from_iter(vec![String::from("reset_button")])
349+
);
348350
assert_eq!(reset_button.direction, D::In);
349351
assert_eq!(reset_button.active_low, true);
350352
assert_eq!(reset_button.export, true);
@@ -385,9 +387,11 @@ names = ["wildcard"]
385387
fn test_parser_compact() {
386388
let config = GpioConfig::from_str(COMPACT_CFG).unwrap();
387389
let status_led = config.pins.get(1).unwrap();
388-
let names = BTreeSet::from_iter(vec![String::from("status_led"),
389-
String::from("A27"),
390-
String::from("green_led")]);
390+
let names = BTreeSet::from_iter(vec![
391+
String::from("status_led"),
392+
String::from("A27"),
393+
String::from("green_led"),
394+
]);
391395
assert_eq!(status_led.names, names);
392396
assert_eq!(status_led.direction, D::Out);
393397
assert_eq!(status_led.active_low, false);
@@ -399,13 +403,9 @@ names = ["wildcard"]
399403
fn test_parser_empty_toml() {
400404
let configstr = "";
401405
match GpioConfig::from_str(configstr) {
402-
Ok(pins) => {
403-
assert_eq!(pins.pins, vec![])
404-
},
406+
Ok(pins) => assert_eq!(pins.pins, vec![]),
405407
Err(Error::ParserErrors(_)) => {}
406-
_ => {
407-
panic!("Expected a parsing error")
408-
},
408+
_ => panic!("Expected a parsing error"),
409409
}
410410
}
411411

@@ -447,25 +447,30 @@ names = ["wildcard"]
447447

448448
let reset_button = config.pins.get(0).unwrap();
449449
assert_eq!(reset_button.num, 73);
450-
assert_eq!(reset_button.names,
451-
BTreeSet::from_iter(vec![String::from("reset_button"),
452-
String::from("new_name")]));
450+
assert_eq!(
451+
reset_button.names,
452+
BTreeSet::from_iter(vec![String::from("reset_button"), String::from("new_name")])
453+
);
453454
assert_eq!(reset_button.direction, D::In);
454455
assert_eq!(reset_button.active_low, false);
455456
assert_eq!(reset_button.export, true);
456457

457458
let status_led = config.pins.get(1).unwrap();
458-
let names = BTreeSet::from_iter(vec![String::from("status_led"),
459-
String::from("A27"),
460-
String::from("green_led")]);
459+
let names = BTreeSet::from_iter(vec![
460+
String::from("status_led"),
461+
String::from("A27"),
462+
String::from("green_led"),
463+
]);
461464
assert_eq!(status_led.names, names);
462465
assert_eq!(status_led.direction, D::In);
463466
assert_eq!(status_led.active_low, false);
464467
assert_eq!(status_led.export, true);
465468

466469
let wildcard = config.pins.get(2).unwrap();
467470
assert_eq!(wildcard.num, 88);
468-
assert_eq!(wildcard.names,
469-
BTreeSet::from_iter(vec![String::from("wildcard")]));
471+
assert_eq!(
472+
wildcard.names,
473+
BTreeSet::from_iter(vec![String::from("wildcard")])
474+
);
470475
}
471476
}

0 commit comments

Comments
 (0)