Skip to content

Commit 4da2e02

Browse files
committed
Errno aliases are now associated consts of the Errno type.
Previously they had to be consts in the errno module, because associated consts weren't supported until Rust 1.20.0. Now that they're associated consts, they can be used interchangeably with regular Errno enum variants.
1 parent 5494b74 commit 4da2e02

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
4040
(#[1440](https://github.com/nix-rust/nix/pull/1440))
4141
- Minimum supported Rust version is now 1.41.0.
4242
([#1440](https://github.com/nix-rust/nix/pull/1440))
43+
- Errno aliases are now associated consts on `Errno`, instead of consts in the
44+
`errno` module.`
45+
(#[1452](https://github.com/nix-rust/nix/pull/1452))
4346

4447
### Fixed
4548
- Allow `sockaddr_ll` size, as reported by the Linux kernel, to be smaller then it's definition

src/errno.rs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,11 @@ mod consts {
843843
EHWPOISON = libc::EHWPOISON,
844844
}
845845

846-
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
847-
pub const EDEADLOCK: Errno = Errno::EDEADLK;
848-
pub const ENOTSUP: Errno = Errno::EOPNOTSUPP;
846+
impl Errno {
847+
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
848+
pub const EDEADLOCK: Errno = Errno::EDEADLK;
849+
pub const ENOTSUP: Errno = Errno::EOPNOTSUPP;
850+
}
849851

850852
pub fn from_i32(e: i32) -> Errno {
851853
use self::Errno::*;
@@ -1103,9 +1105,11 @@ mod consts {
11031105
EQFULL = libc::EQFULL,
11041106
}
11051107

1106-
pub const ELAST: Errno = Errno::EQFULL;
1107-
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1108-
pub const EDEADLOCK: Errno = Errno::EDEADLK;
1108+
impl Errno {
1109+
pub const ELAST: Errno = Errno::EQFULL;
1110+
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1111+
pub const EDEADLOCK: Errno = Errno::EDEADLK;
1112+
}
11091113

11101114
pub fn from_i32(e: i32) -> Errno {
11111115
use self::Errno::*;
@@ -1326,9 +1330,11 @@ mod consts {
13261330
EOWNERDEAD = libc::EOWNERDEAD,
13271331
}
13281332

1329-
pub const ELAST: Errno = Errno::EOWNERDEAD;
1330-
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1331-
pub const EDEADLOCK: Errno = Errno::EDEADLK;
1333+
impl Errno {
1334+
pub const ELAST: Errno = Errno::EOWNERDEAD;
1335+
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1336+
pub const EDEADLOCK: Errno = Errno::EDEADLK;
1337+
}
13321338

13331339
pub fn from_i32(e: i32) -> Errno {
13341340
use self::Errno::*;
@@ -1538,10 +1544,12 @@ mod consts {
15381544
EASYNC = libc::EASYNC,
15391545
}
15401546

1541-
pub const ELAST: Errno = Errno::EASYNC;
1542-
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1543-
pub const EDEADLOCK: Errno = Errno::EDEADLK;
1544-
pub const EOPNOTSUPP: Errno = Errno::ENOTSUP;
1547+
impl Errno {
1548+
pub const ELAST: Errno = Errno::EASYNC;
1549+
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1550+
pub const EDEADLOCK: Errno = Errno::EDEADLK;
1551+
pub const EOPNOTSUPP: Errno = Errno::ENOTSUP;
1552+
}
15451553

15461554
pub fn from_i32(e: i32) -> Errno {
15471555
use self::Errno::*;
@@ -1750,8 +1758,10 @@ mod consts {
17501758
EPROTO = libc::EPROTO,
17511759
}
17521760

1753-
pub const ELAST: Errno = Errno::ENOTSUP;
1754-
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1761+
impl Errno {
1762+
pub const ELAST: Errno = Errno::ENOTSUP;
1763+
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1764+
}
17551765

17561766
pub fn from_i32(e: i32) -> Errno {
17571767
use self::Errno::*;
@@ -1961,8 +1971,10 @@ mod consts {
19611971
EPROTO = libc::EPROTO,
19621972
}
19631973

1964-
pub const ELAST: Errno = Errno::ENOTSUP;
1965-
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1974+
impl Errno {
1975+
pub const ELAST: Errno = Errno::ENOTSUP;
1976+
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
1977+
}
19661978

19671979
pub fn from_i32(e: i32) -> Errno {
19681980
use self::Errno::*;
@@ -2162,7 +2174,9 @@ mod consts {
21622174
EPROTO = libc::EPROTO,
21632175
}
21642176

2165-
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
2177+
impl Errno {
2178+
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
2179+
}
21662180

21672181
pub fn from_i32(e: i32) -> Errno {
21682182
use self::Errno::*;
@@ -2387,8 +2401,10 @@ mod consts {
23872401
ESTALE = libc::ESTALE,
23882402
}
23892403

2390-
pub const ELAST: Errno = Errno::ESTALE;
2391-
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
2404+
impl Errno {
2405+
pub const ELAST: Errno = Errno::ESTALE;
2406+
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
2407+
}
23922408

23932409
pub fn from_i32(e: i32) -> Errno {
23942410
use self::Errno::*;

0 commit comments

Comments
 (0)