Skip to content

Commit 6efbed0

Browse files
committed
Merge pull request #12 from rust-embedded/use-str-over-string
Use str over string
2 parents 95ef6ab + 03fb86a commit 6efbed0

File tree

11 files changed

+79
-71
lines changed

11 files changed

+79
-71
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Linux GPIO Utils
22

3+
[![Build Status](https://travis-ci.org/rust-embedded/gpio-utils.svg?branch=master)](https://travis-ci.org/rust-embedded/gpio-utils)
4+
[![Version](https://img.shields.io/crates/v/gpio-utils.svg?maxAge=2592000)](https://crates.io/crates/gpio-utils)
5+
[![License](https://img.shields.io/crates/l/rustc-serialize.svg?maxAge=2592000)](https://github.com/rust-embedded/gpio-utils/blob/master/README.md#license)
6+
37
GPIO Utils provides convenient access to GPIOs on a Linux system. The library
48
builds on top of the sysfs interface to GPIOs exposed by the kernel and provides
59
essential functionality required for most embedded systems.
@@ -15,15 +19,15 @@ cargo install gpio-utils
1519

1620
## Features
1721

18-
- [ ] Infrastructure for providing names for the GPIOs in one's system providing
22+
- [x] Infrastructure for providing names for the GPIOs in one's system providing
1923
names that map to individual pins. These names (in addition to GPIO numbers)
2024
may be used with other commands.
21-
- [ ] Ability to export/unexport GPIOs and expose symlinks using the GPIO "friendly"
25+
- [x] Ability to export/unexport GPIOs and expose symlinks using the GPIO "friendly"
2226
names simpler.
23-
- [ ] Ability to set input/output state on each pin
24-
- [ ] Ability to get/set gpio values by pin number or name (including temporary
27+
- [x] Ability to set input/output state on each pin
28+
- [x] Ability to get/set gpio values by pin number or name (including temporary
2529
export if necessary)
26-
- [ ] Ability to block awaiting pin state change (with timeout)
30+
- [x] Ability to block awaiting pin state change (with timeout)
2731

2832
## System Integration
2933

src/commands/gpio_export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::process::exit;
1212
use export;
1313

1414
pub fn main(config: &GpioConfig, opts: &GpioExportOptions) {
15-
let pin = match config.get_pin(&opts.pin[..]) {
15+
let pin = match config.get_pin(opts.pin) {
1616
Some(pin) => pin,
1717
None => {
1818
println!("Unable to find config entry for pin '{}'", opts.pin);
@@ -21,7 +21,7 @@ pub fn main(config: &GpioConfig, opts: &GpioExportOptions) {
2121
};
2222

2323
let symlink_root = match opts.symlink_root {
24-
Some(ref slr) => &slr[..],
24+
Some(slr) => slr,
2525
None => config.get_symlink_root(),
2626
};
2727

src/commands/gpio_exportall.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use export;
1313

1414
pub fn main(config: &GpioConfig, opts: &GpioExportAllOptions) {
1515
let symlink_root = match opts.symlink_root {
16-
Some(ref slr) => &slr[..],
16+
Some(slr) => slr,
1717
None => config.get_symlink_root(),
1818
};
1919

src/commands/gpio_poll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ use std::process::exit;
1313

1414
pub fn main(config: &GpioConfig, opts: &GpioPollOptions) {
1515
let timeout = opts.timeout.unwrap_or(-1);
16-
let pin_config = match config.get_pin(&opts.pin[..]) {
16+
let pin_config = match config.get_pin(opts.pin) {
1717
Some(pin) => pin,
1818
None => {
1919
println!("Unable to find config entry for pin '{}'", opts.pin);
2020
exit(1)
2121
}
2222
};
2323
let pin = pin_config.get_pin();
24-
let edge = match &opts.edge[..] {
24+
let edge = match opts.edge {
2525
"rising" => Edge::RisingEdge,
2626
"falling" => Edge::FallingEdge,
2727
"both" => Edge::BothEdges,

src/commands/gpio_read.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use config::GpioConfig;
1111
use std::process::exit;
1212

1313
pub fn main(config: &GpioConfig, opts: &GpioReadOptions) {
14-
let pin_config = match config.get_pin(&opts.pin[..]) {
14+
let pin_config = match config.get_pin(opts.pin) {
1515
Some(pin) => pin,
1616
None => {
1717
println!("Unable to find config entry for pin '{}'", opts.pin);

src/commands/gpio_status.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::process::exit;
1515
pub fn main(config: &GpioConfig, opts: &GpioStatusOptions) {
1616
match opts.pin {
1717
Some(ref pin_name) => {
18-
let pin_config = match config.get_pin(&pin_name[..]) {
18+
let pin_config = match config.get_pin(pin_name) {
1919
Some(pin) => pin,
2020
None => {
2121
println!("Unable to find config entry for pin '{}'", pin_name);
@@ -24,7 +24,7 @@ pub fn main(config: &GpioConfig, opts: &GpioStatusOptions) {
2424
};
2525
print_pin_header();
2626
print_pin_row(&pin_config, true);
27-
},
27+
}
2828
None => {
2929
print_pin_header();
3030
for (pos, pin) in config.get_pins().iter().enumerate() {
@@ -35,20 +35,24 @@ pub fn main(config: &GpioConfig, opts: &GpioStatusOptions) {
3535
}
3636

3737

38-
fn print_pin_header(){
39-
println!("| {:<10} | {:<10} | {:<10} | {:<10} | {:<10} | {:<10} |",
40-
"Number",
41-
"Exported",
42-
"Direction",
43-
"Active Low",
44-
"Names",
38+
fn print_pin_header() {
39+
println!("| {:<10} | {:<10} | {:<10} | {:<10} | {:<10} | {:<10} |",
40+
"Number",
41+
"Exported",
42+
"Direction",
43+
"Active Low",
44+
"Names",
4545
"Value");
4646
print_row_sep(false);
4747
}
4848

49-
fn print_row_sep(is_last: bool){
50-
let col_sep = if is_last {"-"} else {"+"};
51-
println!("{}{:->13}{:->13}{:->13}{:->13}{:->13}{:->13}",
49+
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}",
5256
col_sep,
5357
col_sep,
5458
col_sep,
@@ -58,7 +62,7 @@ fn print_row_sep(is_last: bool){
5862
col_sep);
5963
}
6064

61-
fn print_pin_row(pin_config: &PinConfig, is_last: bool){
65+
fn print_pin_row(pin_config: &PinConfig, is_last: bool) {
6266
let direction = match pin_config.direction {
6367
Direction::In => "In",
6468
Direction::Out => "Out",
@@ -71,25 +75,25 @@ fn print_pin_row(pin_config: &PinConfig, is_last: bool){
7175
Err(e) => {
7276
println!("ERROR: {:?}", e);
7377
exit(1);
74-
},
78+
}
7579
};
7680

7781
for (pos, name) in pin_config.names.iter().enumerate() {
7882
if pos == 0 {
79-
println!("| {:<10} | {:<10} | {:<10} | {:<10} | {:<10} | {:<10} |",
80-
pin_config.num,
81-
pin_config.export,
82-
direction,
83-
pin_config.active_low,
84-
name,
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,
8589
value);
8690
} else {
87-
println!("| {:<10} | {:<10} | {:<10} | {:<10} | {:<10} | {:<10} |",
88-
"",
89-
"",
90-
"",
91-
"",
92-
name,
91+
println!("| {:<10} | {:<10} | {:<10} | {:<10} | {:<10} | {:<10} |",
92+
"",
93+
"",
94+
"",
95+
"",
96+
name,
9397
"");
9498

9599
}

src/commands/gpio_unexport.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ use std::process::exit;
1212
use export;
1313

1414
pub fn main(config: &GpioConfig, opts: &GpioUnexportOptions) {
15-
let pin_config = config.get_pin(&opts.pin[..]).unwrap_or_else(|| {
15+
let pin_config = config.get_pin(opts.pin).unwrap_or_else(|| {
1616
println!("Unable to find config entry for pin '{}'", opts.pin);
1717
exit(1)
1818
});
1919

2020
let symlink_root = match opts.symlink_root {
21-
Some(ref slr) => &slr[..],
21+
Some(slr) => slr,
2222
None => config.get_symlink_root(),
2323
};
2424

src/commands/gpio_unexportall.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use export;
1313

1414
pub fn main(config: &GpioConfig, opts: &GpioUnexportAllOptions) {
1515
let symlink_root = match opts.symlink_root {
16-
Some(ref slr) => &slr[..],
16+
Some(slr) => slr,
1717
None => config.get_symlink_root(),
1818
};
1919

src/commands/gpio_write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::process::exit;
1212
use sysfs_gpio::Direction;
1313

1414
pub fn main(config: &GpioConfig, opts: &GpioWriteOptions) {
15-
let pin_config = match config.get_pin(&opts.pin[..]) {
15+
let pin_config = match config.get_pin(opts.pin) {
1616
Some(pin) => pin,
1717
None => {
1818
println!("Unable to find config entry for pin '{}'", opts.pin);

src/main.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn main() {
154154
("read", Some(m)) => {
155155
let read_options = GpioReadOptions {
156156
gpio_opts: gpio_options,
157-
pin: String::from(m.value_of("pin").unwrap()),
157+
pin: m.value_of("pin").unwrap(),
158158
};
159159
gpio_read::main(&cfg, &read_options);
160160
}
@@ -167,16 +167,16 @@ fn main() {
167167
});
168168
let poll_options = GpioPollOptions {
169169
gpio_opts: gpio_options,
170-
edge: String::from(m.value_of("edge").unwrap_or("both")),
170+
edge: m.value_of("edge").unwrap_or("both"),
171171
timeout: timeout,
172-
pin: String::from(m.value_of("pin").unwrap()),
172+
pin: m.value_of("pin").unwrap(),
173173
};
174174
gpio_poll::main(&cfg, &poll_options);
175175
}
176176
("write", Some(m)) => {
177177
let write_options = GpioWriteOptions {
178178
gpio_opts: gpio_options,
179-
pin: String::from(m.value_of("pin").unwrap()),
179+
pin: m.value_of("pin").unwrap(),
180180
value: match m.value_of("value").unwrap().parse::<u8>() {
181181
Ok(value) => value,
182182
Err(_) => {
@@ -191,9 +191,9 @@ fn main() {
191191
("export", Some(m)) => {
192192
let export_options = GpioExportOptions {
193193
gpio_opts: gpio_options,
194-
pin: String::from(m.value_of("pin").unwrap()),
194+
pin: m.value_of("pin").unwrap(),
195195
symlink_root: match m.value_of("symlink-root") {
196-
Some(slr) => Some(String::from(slr)),
196+
Some(slr) => Some(slr),
197197
None => None,
198198
},
199199
};
@@ -203,7 +203,7 @@ fn main() {
203203
let exportall_options = GpioExportAllOptions {
204204
gpio_opts: gpio_options,
205205
symlink_root: match m.value_of("symlink-root") {
206-
Some(slr) => Some(String::from(slr)),
206+
Some(slr) => Some(slr),
207207
None => None,
208208
},
209209
};
@@ -212,22 +212,22 @@ fn main() {
212212
("unexport", Some(m)) => {
213213
let unexport_options = GpioUnexportOptions {
214214
gpio_opts: gpio_options,
215-
pin: String::from(m.value_of("pin").unwrap()),
216-
symlink_root: m.value_of("symlink-root").map(String::from),
215+
pin: m.value_of("pin").unwrap(),
216+
symlink_root: m.value_of("symlink-root"),
217217
};
218218
gpio_unexport::main(&cfg, &unexport_options);
219219
}
220220
("unexport-all", Some(m)) => {
221221
let unexportall_options = GpioUnexportAllOptions {
222222
gpio_opts: gpio_options,
223-
symlink_root: m.value_of("symlink-root").map(String::from),
223+
symlink_root: m.value_of("symlink-root"),
224224
};
225225
gpio_unexportall::main(&cfg, &unexportall_options);
226226
}
227227
("status", Some(m)) => {
228228
let status_options = GpioStatusOptions {
229229
gpio_opts: gpio_options,
230-
pin: m.value_of("pin").map(String::from),
230+
pin: m.value_of("pin"),
231231
};
232232
gpio_status::main(&cfg, &status_options);
233233
}

0 commit comments

Comments
 (0)