Rust htons and ntohs
I have a program that relied on native::io::net::{htons, ntohs}
, but now the errors are on Could not find 'io' in 'packet::native'
. It seems like this change happened last week.
Searching does not provide much information about the change, and searching htons
or ntohs
in documents does not provide any useful information.
What's the (new?) Standard way of doing htons
or ntohs
in Rust?
The obvious solution would be to write my own, but one would expect it to be in the standard library.
source to share
You can use functions from_be
and to_be
features Int
. The network order is big endian, so it is equivalent.
You can find usage examples in the documentation for these:
http://doc.rust-lang.org/core/num/trait.Int.html#method.to_be
http://doc.rust-lang.org/core/num/trait.Int.html#method.from_be
source to share