@@ -33,24 +33,20 @@ pub struct LinuxI2CBus {
33
33
devfile : File ,
34
34
}
35
35
36
- /// Linux Errno error.
37
- #[ derive( Debug ) ]
38
- pub struct Errno {
39
- nix : nix:: Error ,
40
- }
41
-
42
36
/// Linux I2C errors
43
37
#[ derive( Debug ) ]
44
38
pub enum LinuxI2CError {
45
- /// OS error
46
- Errno ( Errno ) ,
39
+ /// Errno from a failing libc call. Sourced from `nix`.
40
+ ///
41
+ /// To interpret this value `nix::Error::from_i32` should be used.
42
+ Errno ( i32 ) ,
47
43
/// Input/output error
48
44
Io ( io:: Error ) ,
49
45
}
50
46
51
47
impl From < nix:: Error > for LinuxI2CError {
52
48
fn from ( e : nix:: Error ) -> Self {
53
- LinuxI2CError :: Errno ( Errno { nix : e } )
49
+ LinuxI2CError :: Errno ( e as i32 )
54
50
}
55
51
}
56
52
@@ -64,15 +60,18 @@ impl From<LinuxI2CError> for io::Error {
64
60
fn from ( e : LinuxI2CError ) -> io:: Error {
65
61
match e {
66
62
LinuxI2CError :: Io ( e) => e,
67
- LinuxI2CError :: Errno ( e) => e . nix . into ( ) ,
63
+ LinuxI2CError :: Errno ( e) => io :: Error :: from_raw_os_error ( e ) ,
68
64
}
69
65
}
70
66
}
71
67
72
68
impl fmt:: Display for LinuxI2CError {
73
69
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
74
70
match * self {
75
- LinuxI2CError :: Errno ( ref e) => fmt:: Display :: fmt ( & e. nix , f) ,
71
+ LinuxI2CError :: Errno ( e) => {
72
+ let error = nix:: Error :: from_i32 ( e) ;
73
+ fmt:: Display :: fmt ( & error, f)
74
+ } ,
76
75
LinuxI2CError :: Io ( ref e) => fmt:: Display :: fmt ( e, f) ,
77
76
}
78
77
}
@@ -82,7 +81,7 @@ impl Error for LinuxI2CError {
82
81
fn cause ( & self ) -> Option < & dyn Error > {
83
82
match * self {
84
83
LinuxI2CError :: Io ( ref e) => Some ( e) ,
85
- LinuxI2CError :: Errno ( ref e ) => Some ( & e . nix ) ,
84
+ LinuxI2CError :: Errno ( _ ) => None ,
86
85
}
87
86
}
88
87
}
0 commit comments