INNER CODE UNIT · Rust
to_bytes
Barre/ZeroFS · zerofs/nbd-proto/src/lib.rs:210
fn to_bytes(&self) -> Result<Vec<u8>, CodecError> {
let mut output = vec![0; Self::WIRE_SIZE];
self.encode(&mut output)?;
Ok(output)
}
}
struct Reader<'a>(&'a [u8]);
impl Reader<'_> {
fn take<const N: usize>(&mut self) -> Result<[u8; N], CodecError> {
let (bytes, rest) = self.0.split_first_chunk().ok_or(CodecError::Truncated)?;
self.0 = rest;
Ok(*bytes)
}
}
struct Writer<'a> {
output: &'a mut [u8],