use {ByteCount, Decode, Eos, ErrorKind, Result};
#[derive(Debug)]
pub struct DecodedValue<T>(Option<T>);
impl<T> DecodedValue<T> {
pub fn new(value: T) -> Self {
DecodedValue(Some(value))
}
}
impl<T> Decode for DecodedValue<T> {
type Item = T;
fn decode(&mut self, _buf: &[u8], _eos: Eos) -> Result<(usize, Option<Self::Item>)> {
let item = track_assert_some!(self.0.take(), ErrorKind::DecoderTerminated);
Ok((0, Some(item)))
}
fn has_terminated(&self) -> bool {
self.0.is_none()
}
fn requiring_bytes(&self) -> ByteCount {
ByteCount::Finite(0)
}
}