@@ -124,11 +124,7 @@ pub use errors::*;
124
124
125
125
unsafe fn rstr_lcpy ( dst : * mut libc:: c_char , src : & str , length : usize ) {
126
126
let copylen = min ( src. len ( ) + 1 , length) ;
127
- ptr:: copy_nonoverlapping (
128
- src. as_bytes ( ) . as_ptr ( ) as * const libc:: c_char ,
129
- dst,
130
- copylen - 1 ,
131
- ) ;
127
+ ptr:: copy_nonoverlapping ( src. as_bytes ( ) . as_ptr ( ) . cast ( ) , dst, copylen - 1 ) ;
132
128
slice:: from_raw_parts_mut ( dst, length) [ copylen - 1 ] = 0 ;
133
129
}
134
130
@@ -209,12 +205,12 @@ pub fn chips() -> Result<ChipIterator> {
209
205
210
206
impl Chip {
211
207
/// Open the GPIO Chip at the provided path (e.g. `/dev/gpiochip<N>`)
212
- pub fn new < P : AsRef < Path > > ( path : P ) -> Result < Chip > {
208
+ pub fn new < P : AsRef < Path > > ( path : P ) -> Result < Self > {
213
209
let f = File :: open ( path. as_ref ( ) ) ?;
214
210
let mut info: ffi:: gpiochip_info = unsafe { mem:: zeroed ( ) } ;
215
211
ffi:: gpio_get_chipinfo_ioctl ( f. as_raw_fd ( ) , & mut info) ?;
216
212
217
- Ok ( Chip {
213
+ Ok ( Self {
218
214
inner : Arc :: new ( InnerChip {
219
215
file : f,
220
216
path : path. as_ref ( ) . to_path_buf ( ) ,
@@ -406,11 +402,11 @@ unsafe fn cstrbuf_to_string(buf: &[libc::c_char]) -> Option<String> {
406
402
}
407
403
408
404
impl Line {
409
- fn new ( chip : Arc < InnerChip > , offset : u32 ) -> Result < Line > {
405
+ fn new ( chip : Arc < InnerChip > , offset : u32 ) -> Result < Self > {
410
406
if offset >= chip. lines {
411
407
return Err ( offset_err ( offset) ) ;
412
408
}
413
- Ok ( Line { chip, offset } )
409
+ Ok ( Self { chip, offset } )
414
410
}
415
411
416
412
/// Get info about the line from the kernel.
@@ -491,8 +487,8 @@ impl Line {
491
487
request. consumer_label [ ..] . as_mut_ptr ( ) ,
492
488
consumer,
493
489
request. consumer_label . len ( ) ,
494
- )
495
- } ;
490
+ ) ;
491
+ }
496
492
ffi:: gpio_get_linehandle_ioctl ( self . chip . file . as_raw_fd ( ) , & mut request) ?;
497
493
Ok ( LineHandle {
498
494
line : self . clone ( ) ,
@@ -557,8 +553,8 @@ impl Line {
557
553
request. consumer_label [ ..] . as_mut_ptr ( ) ,
558
554
consumer,
559
555
request. consumer_label . len ( ) ,
560
- )
561
- } ;
556
+ ) ;
557
+ }
562
558
ffi:: gpio_get_lineevent_ioctl ( self . chip . file . as_raw_fd ( ) , & mut request) ?;
563
559
564
560
Ok ( LineEventHandle {
@@ -603,9 +599,10 @@ impl LineInfo {
603
599
/// Lines are considered to be inputs if not explicitly
604
600
/// marked as outputs in the line info flags by the kernel.
605
601
pub fn direction ( & self ) -> LineDirection {
606
- match self . flags . contains ( LineFlags :: IS_OUT ) {
607
- true => LineDirection :: Out ,
608
- false => LineDirection :: In ,
602
+ if self . flags . contains ( LineFlags :: IS_OUT ) {
603
+ LineDirection :: Out
604
+ } else {
605
+ LineDirection :: In
609
606
}
610
607
}
611
608
@@ -667,7 +664,7 @@ impl LineHandle {
667
664
/// This value should be 0 or 1 which a "1" representing that
668
665
/// the line is active. Usually this means that the line is
669
666
/// at logic-level high but it could mean the opposite if the
670
- /// line has been marked as being ACTIVE_LOW.
667
+ /// line has been marked as being ` ACTIVE_LOW` .
671
668
pub fn get_value ( & self ) -> Result < u8 > {
672
669
let mut data: ffi:: gpiohandle_data = unsafe { mem:: zeroed ( ) } ;
673
670
ffi:: gpiohandle_get_line_values_ioctl ( self . file . as_raw_fd ( ) , & mut data) ?;
@@ -678,7 +675,7 @@ impl LineHandle {
678
675
///
679
676
/// The value should be 0 or 1 with 1 representing a request
680
677
/// to make the line "active". Usually "active" means
681
- /// logic level high unless the line has been marked as ACTIVE_LOW.
678
+ /// logic level high unless the line has been marked as ` ACTIVE_LOW` .
682
679
///
683
680
/// Calling `set_value` on a line that is not an output will
684
681
/// likely result in an error (from the kernel).
@@ -701,7 +698,7 @@ impl LineHandle {
701
698
}
702
699
703
700
impl AsRawFd for LineHandle {
704
- /// Gets the raw file descriptor for the LineHandle.
701
+ /// Gets the raw file descriptor for the ` LineHandle` .
705
702
fn as_raw_fd ( & self ) -> RawFd {
706
703
self . file . as_raw_fd ( )
707
704
}
@@ -717,13 +714,13 @@ pub struct Lines {
717
714
}
718
715
719
716
impl Lines {
720
- fn new ( chip : Arc < InnerChip > , offsets : & [ u32 ] ) -> Result < Lines > {
717
+ fn new ( chip : Arc < InnerChip > , offsets : & [ u32 ] ) -> Result < Self > {
721
718
let res: Result < Vec < Line > > = offsets
722
719
. iter ( )
723
720
. map ( |off| Line :: new ( chip. clone ( ) , * off) )
724
721
. collect ( ) ;
725
722
let lines = res?;
726
- Ok ( Lines { lines } )
723
+ Ok ( Self { lines } )
727
724
}
728
725
729
726
/// Get a handle to the parent chip for the lines
@@ -796,12 +793,12 @@ impl Lines {
796
793
request. consumer_label [ ..] . as_mut_ptr ( ) ,
797
794
consumer,
798
795
request. consumer_label . len ( ) ,
799
- )
800
- } ;
796
+ ) ;
797
+ }
801
798
ffi:: gpio_get_linehandle_ioctl ( self . lines [ 0 ] . chip ( ) . inner . file . as_raw_fd ( ) , & mut request) ?;
802
799
let lines = self . lines . clone ( ) ;
803
800
Ok ( MultiLineHandle {
804
- lines : Lines { lines } ,
801
+ lines : Self { lines } ,
805
802
file : unsafe { File :: from_raw_fd ( request. fd ) } ,
806
803
} )
807
804
}
@@ -841,7 +838,7 @@ impl MultiLineHandle {
841
838
/// This value should be 0 or 1 which a "1" representing that
842
839
/// the line is active. Usually this means that the line is
843
840
/// at logic-level high but it could mean the opposite if the
844
- /// line has been marked as being ACTIVE_LOW.
841
+ /// line has been marked as being ` ACTIVE_LOW` .
845
842
pub fn get_values ( & self ) -> Result < Vec < u8 > > {
846
843
let mut data: ffi:: gpiohandle_data = unsafe { mem:: zeroed ( ) } ;
847
844
ffi:: gpiohandle_get_line_values_ioctl ( self . file . as_raw_fd ( ) , & mut data) ?;
@@ -854,7 +851,7 @@ impl MultiLineHandle {
854
851
///
855
852
/// The value should be 0 or 1 with 1 representing a request
856
853
/// to make the line "active". Usually "active" means
857
- /// logic level high unless the line has been marked as ACTIVE_LOW.
854
+ /// logic level high unless the line has been marked as ` ACTIVE_LOW` .
858
855
///
859
856
/// Calling `set_value` on a line that is not an output will
860
857
/// likely result in an error (from the kernel).
@@ -881,7 +878,7 @@ impl MultiLineHandle {
881
878
}
882
879
883
880
impl AsRawFd for MultiLineHandle {
884
- /// Gets the raw file descriptor for the LineHandle.
881
+ /// Gets the raw file descriptor for the ` LineHandle` .
885
882
fn as_raw_fd ( & self ) -> RawFd {
886
883
self . file . as_raw_fd ( )
887
884
}
@@ -923,8 +920,8 @@ impl LineEvent {
923
920
/// in an interrupt handler so it should be very accurate.
924
921
///
925
922
/// The nanosecond timestamp value should are captured
926
- /// using the CLOCK_REALTIME offsets in the kernel and
927
- /// should be compared against CLOCK_REALTIME values.
923
+ /// using the ` CLOCK_REALTIME` offsets in the kernel and
924
+ /// should be compared against ` CLOCK_REALTIME` values.
928
925
pub fn timestamp ( & self ) -> u64 {
929
926
self . 0 . timestamp
930
927
}
@@ -974,7 +971,7 @@ impl LineEventHandle {
974
971
/// This value should be 0 or 1 which a "1" representing that
975
972
/// the line is active. Usually this means that the line is
976
973
/// at logic-level high but it could mean the opposite if the
977
- /// line has been marked as being ACTIVE_LOW.
974
+ /// line has been marked as being ` ACTIVE_LOW` .
978
975
pub fn get_value ( & self ) -> Result < u8 > {
979
976
let mut data: ffi:: gpiohandle_data = unsafe { mem:: zeroed ( ) } ;
980
977
ffi:: gpiohandle_get_line_values_ioctl ( self . file . as_raw_fd ( ) , & mut data) ?;
@@ -990,23 +987,23 @@ impl LineEventHandle {
990
987
/// enough data was read or the error returned by `read()`.
991
988
pub ( crate ) fn read_event ( & mut self ) -> std:: io:: Result < Option < LineEvent > > {
992
989
let mut data: ffi:: gpioevent_data = unsafe { mem:: zeroed ( ) } ;
993
- let mut data_as_buf = unsafe {
990
+ let data_as_buf = unsafe {
994
991
slice:: from_raw_parts_mut (
995
- & mut data as * mut ffi:: gpioevent_data as * mut u8 ,
992
+ ( & mut data as * mut ffi:: gpioevent_data ) . cast ( ) ,
996
993
mem:: size_of :: < ffi:: gpioevent_data > ( ) ,
997
994
)
998
995
} ;
999
- let bytes_read = self . file . read ( & mut data_as_buf) ?;
1000
- if bytes_read != mem:: size_of :: < ffi:: gpioevent_data > ( ) {
1001
- Ok ( None )
1002
- } else {
996
+ let bytes_read = self . file . read ( data_as_buf) ?;
997
+ if bytes_read == mem:: size_of :: < ffi:: gpioevent_data > ( ) {
1003
998
Ok ( Some ( LineEvent ( data) ) )
999
+ } else {
1000
+ Ok ( None )
1004
1001
}
1005
1002
}
1006
1003
}
1007
1004
1008
1005
impl AsRawFd for LineEventHandle {
1009
- /// Gets the raw file descriptor for the LineEventHandle.
1006
+ /// Gets the raw file descriptor for the ` LineEventHandle` .
1010
1007
fn as_raw_fd ( & self ) -> RawFd {
1011
1008
self . file . as_raw_fd ( )
1012
1009
}
0 commit comments