Skip to content

Commit 90fba87

Browse files
committed
Mark some functions as const
Because we can.
1 parent 938d6bd commit 90fba87

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/socket.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ impl Socket {
688688
/// Set `SOCK_CLOEXEC` and `NO_HANDLE_INHERIT` on the `ty`pe on platforms that
689689
/// support it.
690690
#[inline(always)]
691-
fn set_common_type(ty: Type) -> Type {
691+
const fn set_common_type(ty: Type) -> Type {
692692
// On platforms that support it set `SOCK_CLOEXEC`.
693693
#[cfg(any(
694694
target_os = "android",
@@ -1006,15 +1006,15 @@ impl Socket {
10061006
}
10071007
}
10081008

1009-
fn from_linger(linger: sys::linger) -> Option<Duration> {
1009+
const fn from_linger(linger: sys::linger) -> Option<Duration> {
10101010
if linger.l_onoff == 0 {
10111011
None
10121012
} else {
10131013
Some(Duration::from_secs(linger.l_linger as u64))
10141014
}
10151015
}
10161016

1017-
fn into_linger(duration: Option<Duration>) -> sys::linger {
1017+
const fn into_linger(duration: Option<Duration>) -> sys::linger {
10181018
match duration {
10191019
Some(duration) => sys::linger {
10201020
l_onoff: 1,

src/sys/unix.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ pub(crate) fn timeout_opt(fd: Socket, opt: c_int, val: c_int) -> io::Result<Opti
823823
unsafe { getsockopt(fd, opt, val).map(from_timeval) }
824824
}
825825

826-
fn from_timeval(duration: libc::timeval) -> Option<Duration> {
826+
const fn from_timeval(duration: libc::timeval) -> Option<Duration> {
827827
if duration.tv_sec == 0 && duration.tv_usec == 0 {
828828
None
829829
} else {
@@ -965,7 +965,7 @@ pub(crate) unsafe fn setsockopt<T>(
965965
.map(|_| ())
966966
}
967967

968-
pub(crate) fn to_in_addr(addr: &Ipv4Addr) -> in_addr {
968+
pub(crate) const fn to_in_addr(addr: &Ipv4Addr) -> in_addr {
969969
// `s_addr` is stored as BE on all machines, and the array is in BE order.
970970
// So the native endian conversion method is used so that it's never
971971
// swapped.
@@ -978,7 +978,7 @@ pub(crate) fn from_in_addr(in_addr: in_addr) -> Ipv4Addr {
978978
Ipv4Addr::from(in_addr.s_addr.to_ne_bytes())
979979
}
980980

981-
pub(crate) fn to_in6_addr(addr: &Ipv6Addr) -> in6_addr {
981+
pub(crate) const fn to_in6_addr(addr: &Ipv6Addr) -> in6_addr {
982982
in6_addr {
983983
s6_addr: addr.octets(),
984984
}
@@ -996,7 +996,7 @@ pub(crate) fn from_in6_addr(addr: in6_addr) -> Ipv6Addr {
996996
target_os = "redox",
997997
target_os = "solaris",
998998
)))]
999-
pub(crate) fn to_mreqn(
999+
pub(crate) const fn to_mreqn(
10001000
multiaddr: &Ipv4Addr,
10011001
interface: &crate::socket::InterfaceIndexOrAddress,
10021002
) -> libc::ip_mreqn {

0 commit comments

Comments
 (0)