asynchronous_codec/
encoder.rs

1use super::fuse::Fuse;
2use bytes::BytesMut;
3use std::io::Error;
4
5/// Encoding of messages as bytes, for use with `FramedWrite`.
6pub trait Encoder {
7    /// The type of items consumed by `encode`
8    type Item;
9    /// The type of encoding errors.
10    type Error: From<Error>;
11
12    /// Encodes an item into the `BytesMut` provided by dst.
13    fn encode(&mut self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error>;
14}
15
16impl<T, U: Encoder> Encoder for Fuse<T, U> {
17    type Item = U::Item;
18    type Error = U::Error;
19
20    fn encode(&mut self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error> {
21        self.u.encode(item, dst)
22    }
23}