use crate::buffer::InputSource;
use crate::decode_from::DecodeFrom;
use crate::Result;
use core::ops::{Deref, DerefMut};
pub struct Decoder<I: InputSource> {
input: I,
}
impl<I: InputSource> Decoder<I> {
pub fn new(underlying: I) -> Self {
Self { input: underlying }
}
pub fn decode<T: DecodeFrom>(&mut self) -> Result<T> {
T::decode_from(self)
}
}
impl<I: InputSource> Deref for Decoder<I> {
type Target = I;
fn deref(&self) -> &Self::Target {
&self.input
}
}
impl<I: InputSource> DerefMut for Decoder<I> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.input
}
}