Skip to content

Commit f832946

Browse files
bors[bot]Erk-
andauthored
Merge #74
74: Update nix to 0.25, hide nix from public API. r=eldruin a=Erk- Hiding nix from the public API will allow to update it in the future without causing a breaking change. Co-authored-by: Valdemar Erk <valdemar@erk.dev> Co-authored-by: Erk <Erk-@users.noreply.github.com>
2 parents efb1090 + 4e3660b commit f832946

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).
88

99
## [Unreleased]
1010

11+
- Hide nix from the public api such that it can be updated without resulting in a breaking change.
12+
- Updated nix to version `0.25`.
1113
- Updated nix to version `0.24`; only use the `ioctl` feature.
1214
- Use `File.read_exact` instead of `File.read` in `LinuxI2CDevice.read` so that the buffer is filled.
1315

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Provides API for safe access to Linux i2c device interface.
1818
libc = "0.2"
1919
bitflags = "1.3"
2020
byteorder = "1"
21-
nix = { version = "0.24", default-features = false, features = ["ioctl"] }
21+
nix = { version = "0.25", default-features = false, features = ["ioctl"] }
2222

2323
[dev-dependencies]
2424
docopt = "1"

src/linux.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,24 @@ pub struct LinuxI2CBus {
3636
/// Linux I2C errors
3737
#[derive(Debug)]
3838
pub enum LinuxI2CError {
39-
/// OS error
40-
Nix(nix::Error),
39+
/// Errno from a failing `libc` call. Sourced from [`nix`].
40+
///
41+
/// To interpret this value [`nix::errno::from_i32`] should be used.
42+
///
43+
/// The [`Error`] implementation will not return a source
44+
/// for this variant, like the [`Error`] implementation of the underlying `nix` error.
45+
///
46+
/// [`nix`]: https://docs.rs/nix/latest/nix/
47+
/// [`nix::errno::from_i32`]: https://docs.rs/nix/latest/nix/errno/fn.from_i32.html
48+
/// [`Error`]: https://doc.rust-lang.org/std/error/trait.Error.html
49+
Errno(i32),
4150
/// Input/output error
4251
Io(io::Error),
4352
}
4453

4554
impl From<nix::Error> for LinuxI2CError {
4655
fn from(e: nix::Error) -> Self {
47-
LinuxI2CError::Nix(e)
56+
LinuxI2CError::Errno(e as i32)
4857
}
4958
}
5059

@@ -58,15 +67,18 @@ impl From<LinuxI2CError> for io::Error {
5867
fn from(e: LinuxI2CError) -> io::Error {
5968
match e {
6069
LinuxI2CError::Io(e) => e,
61-
LinuxI2CError::Nix(e) => e.into(),
70+
LinuxI2CError::Errno(e) => io::Error::from_raw_os_error(e),
6271
}
6372
}
6473
}
6574

6675
impl fmt::Display for LinuxI2CError {
6776
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6877
match *self {
69-
LinuxI2CError::Nix(ref e) => fmt::Display::fmt(e, f),
78+
LinuxI2CError::Errno(e) => {
79+
let error = nix::Error::from_i32(e);
80+
fmt::Display::fmt(&error, f)
81+
}
7082
LinuxI2CError::Io(ref e) => fmt::Display::fmt(e, f),
7183
}
7284
}
@@ -76,7 +88,7 @@ impl Error for LinuxI2CError {
7688
fn cause(&self) -> Option<&dyn Error> {
7789
match *self {
7890
LinuxI2CError::Io(ref e) => Some(e),
79-
LinuxI2CError::Nix(ref e) => Some(e),
91+
LinuxI2CError::Errno(_) => None,
8092
}
8193
}
8294
}

0 commit comments

Comments
 (0)