Struct BytesCodec

struct BytesCodec(_)

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.

impl Clone for BytesCodec

fn clone(self: &Self) -> BytesCodec

impl Copy for BytesCodec

impl Debug for BytesCodec

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

impl Decoder for BytesCodec

fn decode(self: &mut Self, buf: &mut BytesMut) -> Result<Option<BytesMut>, Error>

impl Default for BytesCodec

fn default() -> BytesCodec

impl Encoder for BytesCodec

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

impl Encoder for BytesCodec

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

impl Eq for BytesCodec

impl Freeze for BytesCodec

impl Hash for BytesCodec

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

impl Ord for BytesCodec

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

impl PartialEq for BytesCodec

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

impl PartialOrd for BytesCodec

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

impl RefUnwindSafe for BytesCodec

impl Send for BytesCodec

impl StructuralPartialEq for BytesCodec

impl Sync for BytesCodec

impl Unpin for BytesCodec

impl UnsafeUnpin for BytesCodec

impl UnwindSafe for BytesCodec

impl<T> Any for BytesCodec

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for BytesCodec

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for BytesCodec

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

impl<T> CloneToUninit for BytesCodec

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

impl<T> From for BytesCodec

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for BytesCodec

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for BytesCodec

fn into(self: 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 for BytesCodec

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

impl<T, U> TryInto for BytesCodec

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