1use crate::buffer::OutputTarget;
4use crate::encode_into::EncodeInto;
5use crate::Result;
6use core::ops::{Deref, DerefMut};
7
8pub struct Encoder<O: OutputTarget> {
10 output: O,
12}
13
14impl<O: OutputTarget> Encoder<O> {
15 pub fn new(underlying: O) -> Self {
17 Self { output: underlying }
18 }
19
20 pub fn encode<T: EncodeInto>(&mut self, value: T) -> Result<()> {
22 value.encode_into(self)
23 }
24}
25
26impl<O: OutputTarget> Deref for Encoder<O> {
28 type Target = O;
29
30 fn deref(&self) -> &Self::Target {
31 &self.output
32 }
33}
34
35impl<O: OutputTarget> DerefMut for Encoder<O> {
37 fn deref_mut(&mut self) -> &mut Self::Target {
38 &mut self.output
39 }
40}