Struct BytesCodec

pub struct BytesCodec(/* private field */);

A simple Decoder and Encoder implementation that just ships bytes around.

Example

Turn an AsyncRead into a stream of Result<BytesMut, Error>.

# mod hidden {
# #[allow(unused_imports)]
use tokio::fs::File;
# }
use tokio::io::AsyncRead;
use tokio_util::codec::{FramedRead, BytesCodec};

# enum File {}
# impl File {
#     async fn open(_name: &str) -> Result<impl AsyncRead, std::io::Error> {
#         use std::io::Cursor;
#         Ok(Cursor::new(vec![0, 1, 2, 3, 4, 5]))
#     }
# }
#
# #[tokio::main(flavor = "current_thread")]
# async fn main() -> Result<(), std::io::Error> {
let my_async_read = File::open("filename.txt").await?;
let my_stream_of_bytes = FramedRead::new(my_async_read, BytesCodec::new());
# Ok(())
# }

Implementations

impl BytesCodec

fn new() -> BytesCodec

Creates a new BytesCodec for shipping around raw bytes.

Trait Implementations

impl Clone for BytesCodec

fn clone(&self) -> BytesCodec

impl Copy for BytesCodec

impl Debug for BytesCodec

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Decoder for BytesCodec

type Item = BytesMut;
type Error = Error;
fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<BytesMut>, Error>

impl Default for BytesCodec

fn default() -> BytesCodec

impl Encoder<Bytes> for BytesCodec

type Error = Error;
fn encode(&mut self, data: Bytes, buf: &mut BytesMut) -> Result<(), Error>

impl Encoder<BytesMut> for BytesCodec

type Error = Error;
fn encode(&mut self, data: BytesMut, buf: &mut BytesMut) -> Result<(), Error>

impl Eq for BytesCodec

impl Hash for BytesCodec

fn hash<__H: Hasher>(&self, state: &mut __H)

impl Ord for BytesCodec

fn cmp(&self, other: &BytesCodec) -> Ordering

impl PartialEq for BytesCodec

fn eq(&self, other: &BytesCodec) -> bool

impl PartialOrd for BytesCodec

fn partial_cmp(&self, other: &BytesCodec) -> Option<Ordering>

impl StructuralPartialEq for BytesCodec

Auto Trait Implementations

impl Freeze for BytesCodec

impl RefUnwindSafe for BytesCodec

impl Send for BytesCodec

impl Sync for BytesCodec

impl Unpin for BytesCodec

impl UnsafeUnpin for BytesCodec

impl UnwindSafe for BytesCodec

Blanket Implementations

impl<T> Any for BytesCodec where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for BytesCodec where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for BytesCodec where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for BytesCodec where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for BytesCodec

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for BytesCodec where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for BytesCodec where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for BytesCodec where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for BytesCodec where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>