# tokio_util::codec::BytesCodec - Rust
API documentation for the Rust `BytesCodec` struct in crate `tokio_util`.
Keywords: rust, rustlang, rust-lang, BytesCodec

# Struct tokio_util::codec::BytesCodec [−] [src]

    pub struct BytesCodec(_);

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

# Example

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

    use tokio::fs::File;
    use tokio::io::AsyncRead;
    use tokio_util::codec::{FramedRead, BytesCodec};

    let my_async_read = File::open("filename.txt").await?;
    let my_stream_of_bytes = FramedRead::new(my_async_read, BytesCodec::new());

## Implementations

### `impl BytesCodec` [src]

#### `pub fn new() -> BytesCodec` [src]

Creates a new `BytesCodec` for shipping around raw bytes.

## Trait Implementations

### `impl Clone for BytesCodec` [src]

#### `fn clone(&self) -> BytesCodec` [src]

Returns a copy of the value. Read more

#### `pub fn clone_from(&mut self, source: &Self)`1.0.0 [src]

Performs copy-assignment from `source`. Read more

### `impl Copy for BytesCodec` [src]

### `impl Debug for BytesCodec` [src]

#### `fn fmt(&self, f: &mut Formatter<'_>) -> Result` [src]

Formats the value using the given formatter. Read more

### `impl Decoder for BytesCodec` [src]

#### `type Item = BytesMut`

The type of decoded frames.

#### `type Error = Error`

The type of unrecoverable frame decoding errors. Read more

#### `fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<BytesMut>, Error>` [src]

Attempts to decode a frame from the provided buffer of bytes. Read more

#### `fn decode_eof(
&mut self,
buf: &mut BytesMut
) -> Result<Option<Self::Item>, Self::Error>` [src]

A default method available to be called when there are no more bytes available to be read from the underlying I/O. Read more

#### `fn framed<T: AsyncRead + AsyncWrite + Sized>(self, io: T) -> Framed<T, Self> where
Self: Sized,` [src]

Provides a `Stream` and `Sink` interface for reading and writing to this `Io` object, using `Decode` and `Encode` to read and write the raw data. Read more

### `impl Default for BytesCodec` [src]

#### `fn default() -> BytesCodec` [src]

Returns the "default value" for a type. Read more

### `impl Encoder<Bytes> for BytesCodec` [src]

#### `type Error = Error`

The type of encoding errors. Read more

#### `fn encode(&mut self, data: Bytes, buf: &mut BytesMut) -> Result<(), Error>` [src]

Encodes a frame into the buffer provided. Read more

### `impl Eq for BytesCodec` [src]

### `impl Hash for BytesCodec` [src]

#### `fn hash<__H: Hasher>(&self, state: &mut __H)` [src]

Feeds this value into the given `Hasher`. Read more

#### `pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,` 1.3.0 [src]

Feeds a slice of this type into the given `Hasher`. Read more

### `impl Ord for BytesCodec` [src]

#### `fn cmp(&self, other: &BytesCodec) -> Ordering` [src]

This method returns an `Ordering` between `self` and `other`. Read more

#### `#[must_use]pub fn max(self, other: Self) -> Self` 1.21.0 [src]

Compares and returns the maximum of two values. Read more

#### `#[must_use]pub fn min(self, other: Self) -> Self` 1.21.0 [src]

Compares and returns the minimum of two values. Read more

#### `#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self` 1.50.0 [src]

Restrict a value to a certain interval. Read more

### `impl PartialEq<BytesCodec> for BytesCodec` [src]

#### `fn eq(&self, other: &BytesCodec) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `fn ne(&self, other: &BytesCodec) -> bool` [src]

This method tests for `!=`.

### `impl PartialOrd<BytesCodec> for BytesCodec` [src]

#### `fn partial_cmp(&self, other: &BytesCodec) -> Option<Ordering>` [src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `fn lt(&self, other: &BytesCodec) -> bool` [src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `fn le(&self, other: &BytesCodec) -> bool` [src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `fn gt(&self, other: &BytesCodec) -> bool` [src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `fn ge(&self, other: &BytesCodec) -> bool` [src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

### `impl StructuralEq for BytesCodec` [src]

### `impl StructuralPartialEq for BytesCodec` [src]

## Auto Trait Implementations

### `impl RefUnwindSafe for BytesCodec` [src]

### `impl Send for BytesCodec` [src]

### `impl Sync for BytesCodec` [src]

### `impl Unpin for BytesCodec` [src]

### `impl UnwindSafe for BytesCodec` [src]

## Blanket Implementations

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `pub fn type_id(&self) -> TypeId` [src]

Gets the `TypeId` of `self`. Read more

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

#### `pub fn borrow(&self) -> &T` [src]

Immutably borrows from an owned value. Read more

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

#### `pub fn borrow_mut(&mut self) -> &mut T` [src]

Mutably borrows from an owned value. Read more

### `impl<T> From<T> for T` [src]

#### `pub fn from(t: T) -> T` [src]

Performs the conversion.

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `pub fn into(self) -> U` [src]

Performs the conversion.

### `impl<T> ToOwned for T where
T: Clone,` [src]

#### `type Owned = T`

The resulting type after obtaining ownership.

#### `pub fn to_owned(&self) -> T` [src]

Creates owned data from borrowed data, usually by cloning. Read more

#### `pub fn clone_into(&self, target: &mut T)` [src]

🔬 This is a nightly-only experimental API. (`toowned_clone_into`)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

#### `pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>` [src]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.

#### `pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>` [src]

Performs the conversion.