[−][src]Struct bytes::buf::Take
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.
Methods
impl<T> Take<T>
[src]
[−]
impl<T> Take<T>
pub fn into_inner(self) -> T
[src]
[−]
pub fn into_inner(self) -> T
Consumes this Take
, returning the underlying value.
Examples
use bytes::{Buf, BufMut}; use std::io::Cursor; let mut buf = Cursor::new(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"[..]);
pub fn get_ref(&self) -> &T
[src]
[−]
pub fn get_ref(&self) -> &T
Gets a reference to the underlying Buf
.
It is inadvisable to directly read from the underlying Buf
.
Examples
use bytes::{Buf, BufMut}; use std::io::Cursor; let mut buf = Cursor::new(b"hello world").take(2); assert_eq!(0, buf.get_ref().position());
pub fn get_mut(&mut self) -> &mut T
[src]
[−]
pub fn get_mut(&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}; use std::io::Cursor; let mut buf = Cursor::new(b"hello world").take(2); let mut dst = vec![]; buf.get_mut().set_position(2); dst.put(&mut buf); assert_eq!(*dst, b"ll"[..]);
pub fn limit(&self) -> usize
[src]
[−]
pub fn limit(&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; use std::io::Cursor; let mut buf = Cursor::new(b"hello world").take(2); assert_eq!(2, buf.limit()); assert_eq!(b'h', buf.get_u8()); assert_eq!(1, buf.limit());
pub fn set_limit(&mut self, lim: usize)
[src]
[−]
pub fn set_limit(&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}; use std::io::Cursor; let mut buf = Cursor::new(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"[..]);
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
[−]
impl<T, U> Into for T where
U: From<T>,
impl<T> From for T
[src]
[−]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
[−]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
[−]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
[−]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
[−]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
[−]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
[−]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
[−]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
[−]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
[−]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more