[][src]Struct bytes::buf::Chain

pub struct Chain<T, U> { /* fields omitted */ }

A Chain sequences two buffers.

Chain is an adapter that links two underlying buffers and provides a continous 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, IntoBuf};
use bytes::buf::Chain;

let buf = Bytes::from(&b"hello "[..]).into_buf()
            .chain(Bytes::from(&b"world"[..]));

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

Methods

impl<T, U> Chain<T, U>[src]

pub fn new(a: T, b: U) -> Chain<T, U>[src]

Creates a new Chain sequencing the provided values.

Examples

use bytes::BytesMut;
use bytes::buf::Chain;

let buf = Chain::new(
    BytesMut::with_capacity(1024),
    BytesMut::with_capacity(1024));

// Use the chained buffer

pub fn first_ref(&self) -> &T[src]

Gets a reference to the first underlying Buf.

Examples

use bytes::{Bytes, Buf, IntoBuf};

let buf = Bytes::from(&b"hello"[..]).into_buf()
            .chain(Bytes::from(&b"world"[..]));

assert_eq!(buf.first_ref().get_ref()[..], b"hello"[..]);

pub fn first_mut(&mut self) -> &mut T[src]

Gets a mutable reference to the first underlying Buf.

Examples

use bytes::{Bytes, Buf, IntoBuf};

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

buf.first_mut().set_position(1);

let full: Bytes = buf.collect();
assert_eq!(full[..], b"ello world"[..]);

pub fn last_ref(&self) -> &U[src]

Gets a reference to the last underlying Buf.

Examples

use bytes::{Bytes, Buf, IntoBuf};

let buf = Bytes::from(&b"hello"[..]).into_buf()
            .chain(Bytes::from(&b"world"[..]));

assert_eq!(buf.last_ref().get_ref()[..], b"world"[..]);

pub fn last_mut(&mut self) -> &mut U[src]

Gets a mutable reference to the last underlying Buf.

Examples

use bytes::{Bytes, Buf, IntoBuf};

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

buf.last_mut().set_position(1);

let full: Bytes = buf.collect();
assert_eq!(full[..], b"hello orld"[..]);

pub fn into_inner(self) -> (T, U)[src]

Consumes this Chain, returning the underlying values.

Examples

use bytes::{Bytes, Buf, IntoBuf};

let buf = Bytes::from(&b"hello"[..]).into_buf()
            .chain(Bytes::from(&b"world"[..]));

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

Trait Implementations

impl<T, U> Buf for Chain<T, U> where
    T: Buf,
    U: Buf
[src]

impl<T, U> BufMut for Chain<T, U> where
    T: BufMut,
    U: BufMut
[src]

impl<T: Debug, U: Debug> Debug for Chain<T, U>[src]

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

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

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

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.

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.

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

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

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