INNER CODE UNIT · Rust
read
Barre/ZeroFS · zerofs/nbd-proto/src/lib.rs:248
fn read(r: &mut Reader<'_>) -> Result<Self, CodecError>;
fn write(&self, w: &mut Writer<'_>) -> Result<(), CodecError>;
}
macro_rules! scalar {
($ty:ty) => {
impl Scalar for $ty {
const SIZE: usize = std::mem::size_of::<Self>();
fn read(r: &mut Reader<'_>) -> Result<Self, CodecError> {
Ok(Self::from_be_bytes(r.take()?))
}
fn write(&self, w: &mut Writer<'_>) -> Result<(), CodecError> {
w.put(&self.to_be_bytes())
}
}
};
}
scalar!(u16);