@@ -107,7 +107,7 @@ mod async_tokio;
107107pub mod errors; // pub portion is deprecated
108108mod ffi;
109109
110- #[ derive( Debug ) ]
110+ #[ derive( Debug , Clone , Copy , PartialEq ) ]
111111pub enum IoctlKind {
112112 ChipInfo ,
113113 LineInfo ,
@@ -165,9 +165,11 @@ struct InnerChip {
165165/// [`chips()`]: fn.chips.html
166166#[ derive( Debug ) ]
167167pub struct Chip {
168- inner : Arc < Box < InnerChip > > ,
168+ inner : Arc < InnerChip > ,
169169}
170170
171+ /// Iterator over chips
172+ #[ derive( Debug ) ]
171173pub struct ChipIterator {
172174 readdir : ReadDir ,
173175}
@@ -176,7 +178,7 @@ impl Iterator for ChipIterator {
176178 type Item = Result < Chip > ;
177179
178180 fn next ( & mut self ) -> Option < Result < Chip > > {
179- while let Some ( entry) = self . readdir . next ( ) {
181+ for entry in & mut self . readdir {
180182 match entry {
181183 Ok ( entry) => {
182184 if entry
@@ -209,11 +211,11 @@ impl Chip {
209211 /// Open the GPIO Chip at the provided path (e.g. `/dev/gpiochip<N>`)
210212 pub fn new < P : AsRef < Path > > ( path : P ) -> Result < Chip > {
211213 let f = File :: open ( path. as_ref ( ) ) ?;
212- let mut info: ffi:: gpiochip_info = unsafe { mem:: MaybeUninit :: uninit ( ) . assume_init ( ) } ;
214+ let mut info: ffi:: gpiochip_info = unsafe { mem:: zeroed ( ) } ;
213215 ffi:: gpio_get_chipinfo_ioctl ( f. as_raw_fd ( ) , & mut info) ?;
214216
215217 Ok ( Chip {
216- inner : Arc :: new ( Box :: new ( InnerChip {
218+ inner : Arc :: new ( InnerChip {
217219 file : f,
218220 path : path. as_ref ( ) . to_path_buf ( ) ,
219221 name : unsafe {
@@ -227,7 +229,7 @@ impl Chip {
227229 . into_owned ( )
228230 } ,
229231 lines : info. lines ,
230- } ) ) ,
232+ } ) ,
231233 } )
232234 }
233235
@@ -297,8 +299,9 @@ impl Chip {
297299}
298300
299301/// Iterator over GPIO Lines for a given chip.
302+ #[ derive( Debug ) ]
300303pub struct LineIterator {
301- chip : Arc < Box < InnerChip > > ,
304+ chip : Arc < InnerChip > ,
302305 idx : u32 ,
303306}
304307
@@ -327,7 +330,7 @@ impl Iterator for LineIterator {
327330///
328331#[ derive( Debug , Clone ) ]
329332pub struct Line {
330- chip : Arc < Box < InnerChip > > ,
333+ chip : Arc < InnerChip > ,
331334 offset : u32 ,
332335}
333336
@@ -388,7 +391,7 @@ bitflags! {
388391}
389392
390393/// In or Out
391- #[ derive( Debug , PartialEq ) ]
394+ #[ derive( Debug , Clone , Copy , PartialEq ) ]
392395pub enum LineDirection {
393396 In ,
394397 Out ,
@@ -403,7 +406,7 @@ unsafe fn cstrbuf_to_string(buf: &[libc::c_char]) -> Option<String> {
403406}
404407
405408impl Line {
406- fn new ( chip : Arc < Box < InnerChip > > , offset : u32 ) -> Result < Line > {
409+ fn new ( chip : Arc < InnerChip > , offset : u32 ) -> Result < Line > {
407410 if offset >= chip. lines {
408411 return Err ( offset_err ( offset) ) ;
409412 }
@@ -560,8 +563,6 @@ impl Line {
560563
561564 Ok ( LineEventHandle {
562565 line : self . clone ( ) ,
563- handle_flags,
564- event_flags,
565566 file : unsafe { File :: from_raw_fd ( request. fd ) } ,
566567 } )
567568 }
@@ -716,7 +717,7 @@ pub struct Lines {
716717}
717718
718719impl Lines {
719- fn new ( chip : Arc < Box < InnerChip > > , offsets : & [ u32 ] ) -> Result < Lines > {
720+ fn new ( chip : Arc < InnerChip > , offsets : & [ u32 ] ) -> Result < Lines > {
720721 let res: Result < Vec < Line > > = offsets
721722 . iter ( )
722723 . map ( |off| Line :: new ( chip. clone ( ) , * off) )
@@ -730,6 +731,11 @@ impl Lines {
730731 self . lines [ 0 ] . chip ( )
731732 }
732733
734+ /// Get the number of lines in the collection
735+ pub fn is_empty ( & self ) -> bool {
736+ self . lines . is_empty ( )
737+ }
738+
733739 /// Get the number of lines in the collection
734740 pub fn len ( & self ) -> usize {
735741 self . lines . len ( )
@@ -780,6 +786,7 @@ impl Lines {
780786 lines : n as u32 ,
781787 fd : 0 ,
782788 } ;
789+ #[ allow( clippy:: needless_range_loop) ] // clippy does not understand this loop correctly
783790 for i in 0 ..n {
784791 request. lineoffsets [ i] = self . lines [ i] . offset ( ) ;
785792 request. default_values [ i] = default[ i] ;
@@ -795,7 +802,6 @@ impl Lines {
795802 let lines = self . lines . clone ( ) ;
796803 Ok ( MultiLineHandle {
797804 lines : Lines { lines } ,
798- flags,
799805 file : unsafe { File :: from_raw_fd ( request. fd ) } ,
800806 } )
801807 }
@@ -821,7 +827,6 @@ impl Index<usize> for Lines {
821827#[ derive( Debug ) ]
822828pub struct MultiLineHandle {
823829 lines : Lines ,
824- flags : LineRequestFlags ,
825830 file : File ,
826831}
827832
@@ -887,7 +892,7 @@ impl AsRawFd for MultiLineHandle {
887892/// Maps to kernel [`GPIOEVENT_EVENT_*`] definitions.
888893///
889894/// [`GPIOEVENT_EVENT_*`]: https://elixir.bootlin.com/linux/v4.9.127/source/include/uapi/linux/gpio.h#L136
890- #[ derive( Debug , PartialEq ) ]
895+ #[ derive( Debug , Clone , Copy , PartialEq ) ]
891896pub enum EventType {
892897 RisingEdge ,
893898 FallingEdge ,
@@ -947,8 +952,6 @@ impl LineEvent {
947952#[ derive( Debug ) ]
948953pub struct LineEventHandle {
949954 line : Line ,
950- handle_flags : LineRequestFlags ,
951- event_flags : EventRequestFlags ,
952955 file : File ,
953956}
954957
@@ -961,7 +964,7 @@ impl LineEventHandle {
961964 pub fn get_event ( & mut self ) -> Result < LineEvent > {
962965 match self . read_event ( ) {
963966 Ok ( Some ( event) ) => Ok ( event) ,
964- Ok ( None ) => Err ( event_err ( nix:: Error :: Sys ( nix :: errno:: Errno :: EIO ) ) ) ,
967+ Ok ( None ) => Err ( event_err ( nix:: errno:: Errno :: EIO ) ) ,
965968 Err ( e) => Err ( e. into ( ) ) ,
966969 }
967970 }
0 commit comments