Trait fluvio::dataplane::core::bytes::BufExt[][src]

pub trait BufExt: Buf {
    pub fn take(self, limit: usize) -> Take<Self> { ... }
pub fn chain<U>(self, next: U) -> Chain<Self, U>
    where
        U: Buf
, { ... }
pub fn reader(self) -> Reader<Self> { ... } }

Extra methods for implementations of Buf.

Provided methods

pub fn take(self, limit: usize) -> Take<Self>[src]

Creates an adaptor which will read at most limit bytes from self.

This function returns a new instance of Buf which will read at most limit bytes.

Examples

use bytes::{BufMut, buf::BufExt};

let mut buf = b"hello world"[..].take(5);
let mut dst = vec![];

dst.put(&mut buf);
assert_eq!(dst, b"hello");

let mut buf = buf.into_inner();
dst.clear();
dst.put(&mut buf);
assert_eq!(dst, b" world");

pub fn chain<U>(self, next: U) -> Chain<Self, U> where
    U: Buf
[src]

Creates an adaptor which will chain this buffer with another.

The returned Buf instance will first consume all bytes from self. Afterwards the output is equivalent to the output of next.

Examples

use bytes::{Buf, buf::BufExt};

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

let full = chain.to_bytes();
assert_eq!(full.bytes(), b"hello world");

pub fn reader(self) -> Reader<Self>[src]

Creates an adaptor which implements the Read trait for self.

This function returns a new value which implements Read by adapting the Read trait functions to the Buf trait functions. Given that Buf operations are infallible, none of the Read functions will return with Err.

Examples

use bytes::{Bytes, buf::BufExt};
use std::io::Read;

let buf = Bytes::from("hello world");

let mut reader = buf.reader();
let mut dst = [0; 1024];

let num = reader.read(&mut dst).unwrap();

assert_eq!(11, num);
assert_eq!(&dst[..11], &b"hello world"[..]);
Loading content...

Implementors

impl<B> BufExt for B where
    B: Buf + ?Sized
[src]

Loading content...