Struct Chain

struct Chain<T, U> { ... }

A Chain sequences two buffers.

Chain is an adapter that links two underlying buffers and provides a continuous view across both buffers. It is able to sequence either immutable buffers (Buf values) or mutable buffers (BufMut values).

This struct is generally created by calling Buf::chain. Please see that function's documentation for more detail.

Examples

use bytes::{Bytes, Buf};

let mut buf = (&b"hello "[..])
    .chain(&b"world"[..]);

let full: Bytes = buf.copy_to_bytes(11);
assert_eq!(full[..], b"hello world"[..]);

Implementations

impl<T, U> Chain<T, U>

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

Gets a reference to the first underlying Buf.

Examples

use bytes::Buf;

let buf = (&b"hello"[..])
    .chain(&b"world"[..]);

assert_eq!(buf.first_ref()[..], b"hello"[..]);
fn first_mut(self: &mut Self) -> &mut T

Gets a mutable reference to the first underlying Buf.

Examples

use bytes::Buf;

let mut buf = (&b"hello"[..])
    .chain(&b"world"[..]);

buf.first_mut().advance(1);

let full = buf.copy_to_bytes(9);
assert_eq!(full, b"elloworld"[..]);
fn last_ref(self: &Self) -> &U

Gets a reference to the last underlying Buf.

Examples

use bytes::Buf;

let buf = (&b"hello"[..])
    .chain(&b"world"[..]);

assert_eq!(buf.last_ref()[..], b"world"[..]);
fn last_mut(self: &mut Self) -> &mut U

Gets a mutable reference to the last underlying Buf.

Examples

use bytes::Buf;

let mut buf = (&b"hello "[..])
    .chain(&b"world"[..]);

buf.last_mut().advance(1);

let full = buf.copy_to_bytes(10);
assert_eq!(full, b"hello orld"[..]);
fn into_inner(self: Self) -> (T, U)

Consumes this Chain, returning the underlying values.

Examples

use bytes::Buf;

let chain = (&b"hello"[..])
    .chain(&b"world"[..]);

let (first, last) = chain.into_inner();
assert_eq!(first[..], b"hello"[..]);
assert_eq!(last[..], b"world"[..]);

impl<T> Any for Chain<T, U>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Chain<T, U>

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

impl<T> BorrowMut for Chain<T, U>

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

impl<T> From for Chain<T, U>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Buf for Chain<T, U>

fn remaining(self: &Self) -> usize
fn chunk(self: &Self) -> &[u8]
fn advance(self: &mut Self, cnt: usize)
fn chunks_vectored<'a>(self: &'a Self, dst: &mut [IoSlice<'a>]) -> usize
fn copy_to_bytes(self: &mut Self, len: usize) -> Bytes

impl<T, U> BufMut for Chain<T, U>

fn remaining_mut(self: &Self) -> usize
fn chunk_mut(self: &mut Self) -> &mut UninitSlice
unsafe fn advance_mut(self: &mut Self, cnt: usize)

impl<T, U> Freeze for Chain<T, U>

impl<T, U> Into for Chain<T, U>

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> IntoIterator for Chain<T, U>

fn into_iter(self: Self) -> <Self as >::IntoIter

impl<T, U> RefUnwindSafe for Chain<T, U>

impl<T, U> Send for Chain<T, U>

impl<T, U> Sync for Chain<T, U>

impl<T, U> TryFrom for Chain<T, U>

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

impl<T, U> TryInto for Chain<T, U>

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

impl<T, U> Unpin for Chain<T, U>

impl<T, U> UnsafeUnpin for Chain<T, U>

impl<T, U> UnwindSafe for Chain<T, U>

impl<T: $crate::fmt::Debug, U: $crate::fmt::Debug> Debug for Chain<T, U>

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