pub trait NetworkRepr<U: Copy> {
// Required methods
fn to_network(self) -> U;
fn from_network(val: U) -> Self;
}Expand description
Types which can be converted to and from bitstrings and byte arrays for serialisation as fields of network packets.
This can be used for better type-checking (e.g., bitfields or newtypes).
We might represent a next-header type using a primitive:
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq, Ord, PartialOrd, Default)]
struct Ethertype(u16);
impl NetworkRepr<u16be> for Ethertype {
#[inline]
fn to_network(self) -> u16be {
self.0
}
#[inline]
fn from_network(val: u16be) -> Self {
Self(val)
}
}…or, a byte array (such as [u8; 16]).
Required Methods§
Sourcefn to_network(self) -> U
fn to_network(self) -> U
Converts a local value into raw bytes or integer type.
Sourcefn from_network(val: U) -> Self
fn from_network(val: U) -> Self
Converts a raw value into a local type.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.