@@ -172,8 +172,8 @@ impl Pin {
172
172
173
173
// determine if this is valid and figure out the pin_num
174
174
if !try!( fs:: metadata ( & pb) ) . is_dir ( ) {
175
- return Err ( Error :: Unexpected ( format ! ( "Provided path not a directory or symlink to \
176
- a directory") ) ) ;
175
+ return Err ( Error :: Unexpected ( "Provided path not a directory or symlink to \
176
+ a directory". to_owned ( ) ) ) ;
177
177
}
178
178
179
179
let re = regex:: Regex :: new ( r"^/sys/.*?/gpio/gpio(\d+)$" ) . unwrap ( ) ;
@@ -268,7 +268,7 @@ impl Pin {
268
268
/// }
269
269
/// ```
270
270
pub fn export ( & self ) -> Result < ( ) > {
271
- if let Err ( _ ) = fs:: metadata ( & format ! ( "/sys/class/gpio/gpio{}" , self . pin_num) ) {
271
+ if fs:: metadata ( & format ! ( "/sys/class/gpio/gpio{}" , self . pin_num) ) . is_err ( ) {
272
272
let mut export_file = try!( File :: create ( "/sys/class/gpio/export" ) ) ;
273
273
try!( export_file. write_all ( format ! ( "{}" , self . pin_num) . as_bytes ( ) ) ) ;
274
274
}
@@ -282,7 +282,7 @@ impl Pin {
282
282
/// exported, it will return without error. That is, whenever
283
283
/// this function returns Ok, the GPIO is not exported.
284
284
pub fn unexport ( & self ) -> Result < ( ) > {
285
- if let Ok ( _ ) = fs:: metadata ( & format ! ( "/sys/class/gpio/gpio{}" , self . pin_num) ) {
285
+ if fs:: metadata ( & format ! ( "/sys/class/gpio/gpio{}" , self . pin_num) ) . is_ok ( ) {
286
286
let mut unexport_file = try!( File :: create ( "/sys/class/gpio/unexport" ) ) ;
287
287
try!( unexport_file. write_all ( format ! ( "{}" , self . pin_num) . as_bytes ( ) ) ) ;
288
288
}
0 commit comments