use crate::buffer::OutputTarget;
use crate::encode_into::EncodeInto;
use crate::Result;
use core::ops::{Deref, DerefMut};
pub struct Encoder<O: OutputTarget> {
output: O,
}
impl<O: OutputTarget> Encoder<O> {
pub fn new(underlying: O) -> Self {
Self { output: underlying }
}
pub fn encode<T: EncodeInto>(&mut self, value: T) -> Result<()> {
value.encode_into(self)
}
}
impl<O: OutputTarget> Deref for Encoder<O> {
type Target = O;
fn deref(&self) -> &Self::Target {
&self.output
}
}
impl<O: OutputTarget> DerefMut for Encoder<O> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.output
}
}