Struct Take

struct Take<T> { ... }

A Buf adapter which limits the bytes read from an underlying buffer.

This struct is generally created by calling take() on Buf. See documentation of take() for more details.

Implementations

impl<T> Take<T>

fn into_inner(self: Self) -> T

Consumes this Take, returning the underlying value.

Examples

use bytes::{Buf, BufMut};

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

dst.put(&mut buf);
assert_eq!(*dst, b"he"[..]);

let mut buf = buf.into_inner();

dst.clear();
dst.put(&mut buf);
assert_eq!(*dst, b"llo world"[..]);
fn get_ref(self: &Self) -> &T

Gets a reference to the underlying Buf.

It is inadvisable to directly read from the underlying Buf.

Examples

use bytes::Buf;

let buf = b"hello world".take(2);

assert_eq!(11, buf.get_ref().remaining());
fn get_mut(self: &mut Self) -> &mut T

Gets a mutable reference to the underlying Buf.

It is inadvisable to directly read from the underlying Buf.

Examples

use bytes::{Buf, BufMut};

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

buf.get_mut().advance(2);

dst.put(&mut buf);
assert_eq!(*dst, b"ll"[..]);
fn limit(self: &Self) -> usize

Returns the maximum number of bytes that can be read.

Note

If the inner Buf has fewer bytes than indicated by this method then that is the actual number of available bytes.

Examples

use bytes::Buf;

let mut buf = b"hello world".take(2);

assert_eq!(2, buf.limit());
assert_eq!(b'h', buf.get_u8());
assert_eq!(1, buf.limit());
fn set_limit(self: &mut Self, lim: usize)

Sets the maximum number of bytes that can be read.

Note

If the inner Buf has fewer bytes than lim then that is the actual number of available bytes.

Examples

use bytes::{Buf, BufMut};

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

dst.put(&mut buf);
assert_eq!(*dst, b"he"[..]);

dst.clear();

buf.set_limit(3);
dst.put(&mut buf);
assert_eq!(*dst, b"llo"[..]);

impl<T> Any for Take<T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Take<T>

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

impl<T> BorrowMut for Take<T>

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

impl<T> Freeze for Take<T>

impl<T> From for Take<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> RefUnwindSafe for Take<T>

impl<T> Send for Take<T>

impl<T> Sync for Take<T>

impl<T> Unpin for Take<T>

impl<T> UnsafeUnpin for Take<T>

impl<T> UnwindSafe for Take<T>

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

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 Take<T>

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

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

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

impl<T: $crate::fmt::Debug> Debug for Take<T>

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

impl<T: Buf> Buf for Take<T>

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