diff options
| author | Lzu Tao <taolzu@gmail.com> | 2019-12-15 12:47:40 +0000 |
|---|---|---|
| committer | Lzu Tao <taolzu@gmail.com> | 2019-12-15 13:41:32 +0000 |
| commit | 3594d8b8a14d48c8aec90a2e702cf312ea2d7f02 (patch) | |
| tree | a0189efbf79f7406330c29c08fdb0f3c78b11636 /src/libstd/net/mod.rs | |
| parent | a605441e049f0b6d5f7715b94b8ac4662fd7fcf6 (diff) | |
| download | rust-3594d8b8a14d48c8aec90a2e702cf312ea2d7f02.tar.gz rust-3594d8b8a14d48c8aec90a2e702cf312ea2d7f02.zip | |
make htons const fn
Diffstat (limited to 'src/libstd/net/mod.rs')
| -rw-r--r-- | src/libstd/net/mod.rs | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/src/libstd/net/mod.rs b/src/libstd/net/mod.rs index b68146939fd..8652ed8b046 100644 --- a/src/libstd/net/mod.rs +++ b/src/libstd/net/mod.rs @@ -85,21 +85,10 @@ pub enum Shutdown { Both, } -#[doc(hidden)] -trait NetInt { - fn from_be(i: Self) -> Self; - fn to_be(&self) -> Self; -} -macro_rules! doit { - ($($t:ident)*) => ($(impl NetInt for $t { - fn from_be(i: Self) -> Self { <$t>::from_be(i) } - fn to_be(&self) -> Self { <$t>::to_be(*self) } - })*) -} -doit! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize } - -fn hton<I: NetInt>(i: I) -> I { i.to_be() } -fn ntoh<I: NetInt>(i: I) -> I { I::from_be(i) } +#[inline] +const fn htons(i: u16) -> u16 { i.to_be() } +#[inline] +const fn ntohs(i: u16) -> u16 { u16::from_be(i) } fn each_addr<A: ToSocketAddrs, F, T>(addr: A, mut f: F) -> io::Result<T> where F: FnMut(io::Result<&SocketAddr>) -> io::Result<T> |
