Struct bytes::buf::Take [−][src]
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"[..]);
ⓘImportant traits for &'a mut Rpub fn get_ref(&self) -> &T
[src]
[−]
ⓘImportant traits for &'a mut R
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());
ⓘImportant traits for &'a mut Rpub fn get_mut(&mut self) -> &mut T
[src]
[−]
ⓘImportant traits for &'a mut R
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"[..]);