Skip to content

Commit 7049d42

Browse files
committed
constify more functions
Constify more functions, since we're raising the MSRV from 1.41.0 to 1.46.0. Fixes #1477
1 parent 5495bbc commit 7049d42

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
4444

4545
- Many more functions, mostly contructors, are now `const`.
4646
(#[1476](https://github.com/nix-rust/nix/pull/1476))
47+
(#[1492](https://github.com/nix-rust/nix/pull/1492))
4748

4849
- `sys::event::KEvent::filter` now returns a `Result` instead of being
4950
infalliable. The only cases where it will now return an error are cases

src/errno.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Errno {
9393
desc(self)
9494
}
9595

96-
pub fn from_i32(err: i32) -> Errno {
96+
pub const fn from_i32(err: i32) -> Errno {
9797
from_i32(err)
9898
}
9999

@@ -928,7 +928,7 @@ mod consts {
928928
pub const ENOTSUP: Errno = Errno::EOPNOTSUPP;
929929
}
930930

931-
pub fn from_i32(e: i32) -> Errno {
931+
pub const fn from_i32(e: i32) -> Errno {
932932
use self::Errno::*;
933933

934934
match e {
@@ -1207,7 +1207,7 @@ mod consts {
12071207
pub const EDEADLOCK: Errno = Errno::EDEADLK;
12081208
}
12091209

1210-
pub fn from_i32(e: i32) -> Errno {
1210+
pub const fn from_i32(e: i32) -> Errno {
12111211
use self::Errno::*;
12121212

12131213
match e {
@@ -1455,7 +1455,7 @@ mod consts {
14551455
pub const EOPNOTSUPP: Errno = Errno::ENOTSUP;
14561456
}
14571457

1458-
pub fn from_i32(e: i32) -> Errno {
1458+
pub const fn from_i32(e: i32) -> Errno {
14591459
use self::Errno::*;
14601460

14611461
match e {
@@ -1692,7 +1692,7 @@ mod consts {
16921692
pub const EOPNOTSUPP: Errno = Errno::ENOTSUP;
16931693
}
16941694

1695-
pub fn from_i32(e: i32) -> Errno {
1695+
pub const fn from_i32(e: i32) -> Errno {
16961696
use self::Errno::*;
16971697

16981698
match e {
@@ -1916,7 +1916,7 @@ mod consts {
19161916
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
19171917
}
19181918

1919-
pub fn from_i32(e: i32) -> Errno {
1919+
pub const fn from_i32(e: i32) -> Errno {
19201920
use self::Errno::*;
19211921

19221922
match e {
@@ -2141,7 +2141,7 @@ mod consts {
21412141
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
21422142
}
21432143

2144-
pub fn from_i32(e: i32) -> Errno {
2144+
pub const fn from_i32(e: i32) -> Errno {
21452145
use self::Errno::*;
21462146

21472147
match e {
@@ -2350,7 +2350,7 @@ mod consts {
23502350
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
23512351
}
23522352

2353-
pub fn from_i32(e: i32) -> Errno {
2353+
pub const fn from_i32(e: i32) -> Errno {
23542354
use self::Errno::*;
23552355

23562356
match e {
@@ -2590,7 +2590,7 @@ mod consts {
25902590
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
25912591
}
25922592

2593-
pub fn from_i32(e: i32) -> Errno {
2593+
pub const fn from_i32(e: i32) -> Errno {
25942594
use self::Errno::*;
25952595

25962596
match e {

src/sys/signal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl Signal {
133133
/// This function is equivalent to `<Signal as AsRef<str>>::as_ref()`,
134134
/// with difference that returned string is `'static`
135135
/// and not bound to `self`'s lifetime.
136-
pub fn as_str(self) -> &'static str {
136+
pub const fn as_str(self) -> &'static str {
137137
match self {
138138
Signal::SIGHUP => "SIGHUP",
139139
Signal::SIGINT => "SIGINT",

src/sys/socket/addr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl AddressFamily {
237237
///
238238
/// Currently only supports these address families: Unix, Inet (v4 & v6), Netlink, Link/Packet
239239
/// and System. Returns None for unsupported or unknown address families.
240-
pub fn from_i32(family: i32) -> Option<AddressFamily> {
240+
pub const fn from_i32(family: i32) -> Option<AddressFamily> {
241241
match family {
242242
libc::AF_UNIX => Some(AddressFamily::Unix),
243243
libc::AF_INET => Some(AddressFamily::Inet),
@@ -314,15 +314,15 @@ impl InetAddr {
314314
}
315315
}
316316
/// Gets the IP address associated with this socket address.
317-
pub fn ip(&self) -> IpAddr {
317+
pub const fn ip(&self) -> IpAddr {
318318
match *self {
319319
InetAddr::V4(ref sa) => IpAddr::V4(Ipv4Addr(sa.sin_addr)),
320320
InetAddr::V6(ref sa) => IpAddr::V6(Ipv6Addr(sa.sin6_addr)),
321321
}
322322
}
323323

324324
/// Gets the port number associated with this socket address
325-
pub fn port(&self) -> u16 {
325+
pub const fn port(&self) -> u16 {
326326
match *self {
327327
InetAddr::V6(ref sa) => u16::from_be(sa.sin6_port),
328328
InetAddr::V4(ref sa) => u16::from_be(sa.sin_port),
@@ -393,7 +393,7 @@ impl IpAddr {
393393
}
394394
}
395395

396-
pub fn to_std(&self) -> net::IpAddr {
396+
pub const fn to_std(&self) -> net::IpAddr {
397397
match *self {
398398
IpAddr::V4(ref ip) => net::IpAddr::V4(ip.to_std()),
399399
IpAddr::V6(ref ip) => net::IpAddr::V6(ip.to_std()),

0 commit comments

Comments
 (0)