I have a program that has been relying on native::io::net::{htons, ntohs}
but now errors on Could not find 'io' in 'packet::native'
. The change seems to have happened some time in the last week
Searching doesn't yield much info about the change and a search for htons
or ntohs
in the docs doesn't yield any useful information.
What is the (new?) standard way to perform htons
or ntohs
in Rust?
An obvious solution would be to write my own but one would expect that it would be in the standard library.
These are now in std::sys_common::net
, but std::sys_common
is private. But their implementation in src/libstd/sys/common/net.rs
is very simple:
pub fn htons(u: u16) -> u16 {
u.to_be()
}
pub fn ntohs(u: u16) -> u16 {
Int::from_be(u)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With