Files
tokio/tokio-util/src/codec/encoder.rs
T

26 lines
898 B
Rust
Raw Normal View History

2019-06-27 18:10:29 +01:00
use bytes::BytesMut;
use std::io;
/// Trait of helper objects to write out messages as bytes, for use with
/// [`FramedWrite`].
///
/// [`FramedWrite`]: crate::codec::FramedWrite
2020-03-04 15:54:41 -05:00
pub trait Encoder<Item> {
2019-06-27 18:10:29 +01:00
/// The type of encoding errors.
///
/// [`FramedWrite`] requires `Encoder`s errors to implement `From<io::Error>`
2019-06-27 18:10:29 +01:00
/// in the interest letting it return `Error`s directly.
///
/// [`FramedWrite`]: crate::codec::FramedWrite
2019-06-27 18:10:29 +01:00
type Error: From<io::Error>;
/// Encodes a frame into the buffer provided.
///
/// This method will encode `item` into the byte buffer provided by `dst`.
/// The `dst` provided is an internal buffer of the [`FramedWrite`] instance and
2019-06-27 18:10:29 +01:00
/// will be written out when possible.
///
/// [`FramedWrite`]: crate::codec::FramedWrite
2020-03-04 15:54:41 -05:00
fn encode(&mut self, item: Item, dst: &mut BytesMut) -> Result<(), Self::Error>;
2019-06-27 18:10:29 +01:00
}