Skip to content

Commit e965e03

Browse files
committed
Represent the errno as a i32
1 parent 5e41a49 commit e965e03

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/linux.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,20 @@ pub struct LinuxI2CBus {
3333
devfile: File,
3434
}
3535

36-
/// Linux Errno error.
37-
#[derive(Debug)]
38-
pub struct Errno {
39-
nix: nix::Error,
40-
}
41-
4236
/// Linux I2C errors
4337
#[derive(Debug)]
4438
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),
4743
/// Input/output error
4844
Io(io::Error),
4945
}
5046

5147
impl From<nix::Error> for LinuxI2CError {
5248
fn from(e: nix::Error) -> Self {
53-
LinuxI2CError::Errno(Errno { nix: e })
49+
LinuxI2CError::Errno(e as i32)
5450
}
5551
}
5652

@@ -64,15 +60,18 @@ impl From<LinuxI2CError> for io::Error {
6460
fn from(e: LinuxI2CError) -> io::Error {
6561
match e {
6662
LinuxI2CError::Io(e) => e,
67-
LinuxI2CError::Errno(e) => e.nix.into(),
63+
LinuxI2CError::Errno(e) => io::Error::from_raw_os_error(e),
6864
}
6965
}
7066
}
7167

7268
impl fmt::Display for LinuxI2CError {
7369
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7470
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+
},
7675
LinuxI2CError::Io(ref e) => fmt::Display::fmt(e, f),
7776
}
7877
}
@@ -82,7 +81,7 @@ impl Error for LinuxI2CError {
8281
fn cause(&self) -> Option<&dyn Error> {
8382
match *self {
8483
LinuxI2CError::Io(ref e) => Some(e),
85-
LinuxI2CError::Errno(ref e) => Some(&e.nix),
84+
LinuxI2CError::Errno(_) => None,
8685
}
8786
}
8887
}

0 commit comments

Comments
 (0)