INNER CODE UNIT · Rust
take
Barre/ZeroFS · zerofs/nbd-proto/src/lib.rs:219
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],
offset: usize,
}
impl Writer<'_> {
fn put(&mut self, bytes: &[u8]) -> Result<(), CodecError> {
let end = self
.offset
.checked_add(bytes.len())
.ok_or(CodecError::BufferTooSmall)?;