Struct Take

#[must_use = "readers do nothing unless you `.await` or poll them"]
pub struct Take<R> { /* private fields */ }

Reader for the take method.

Implementations

impl<R: AsyncRead> Take<R>

fn limit(&self) -> u64

Returns the remaining number of bytes that can be read before this instance will return EOF.

Note

This instance may reach EOF after reading fewer bytes than indicated by this method if the underlying AsyncRead instance reaches EOF.

Examples

# futures::executor::block_on(async {
use futures::io::{AsyncReadExt, Cursor};

let reader = Cursor::new(&b"12345678"[..]);
let mut buffer = [0; 2];

let mut take = reader.take(4);
let n = take.read(&mut buffer).await?;

assert_eq!(take.limit(), 2);
# Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
fn set_limit(&mut self, limit: u64)

Sets the number of bytes that can be read before this instance will return EOF. This is the same as constructing a new Take instance, so the amount of bytes read and the previous limit value don't matter when calling this method.

Examples

# futures::executor::block_on(async {
use futures::io::{AsyncReadExt, Cursor};

let reader = Cursor::new(&b"12345678"[..]);
let mut buffer = [0; 4];

let mut take = reader.take(4);
let n = take.read(&mut buffer).await?;

assert_eq!(n, 4);
assert_eq!(take.limit(), 0);

take.set_limit(10);
let n = take.read(&mut buffer).await?;
assert_eq!(n, 4);

# Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
fn get_ref(&self) -> &R

Acquires a reference to the underlying sink or stream that this combinator is pulling from.

fn get_mut(&mut self) -> &mut R

Acquires a mutable reference to the underlying sink or stream that this combinator is pulling from.

Note that care must be taken to avoid tampering with the state of the sink or stream which may otherwise confuse this combinator.

fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut R>

Acquires a pinned mutable reference to the underlying sink or stream that this combinator is pulling from.

Note that care must be taken to avoid tampering with the state of the sink or stream which may otherwise confuse this combinator.

fn into_inner(self) -> R

Consumes this combinator, returning the underlying sink or stream.

Note that this may discard intermediate state of this combinator, so care should be taken to avoid losing resources when this is called.

Trait Implementations

impl<'__pin, R> Unpin for Take<R> where PinnedFieldsOf<__Origin<'__pin, R>>: Unpin,

impl<R: AsyncBufRead> AsyncBufRead for Take<R>

fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<&[u8]>>
fn consume(self: Pin<&mut Self>, amt: usize)

impl<R: AsyncRead> AsyncRead for Take<R>

fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<Result<usize, Error>>

impl<R: Debug> Debug for Take<R>

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

Auto Trait Implementations

impl<R> Freeze for Take<R> where R: Freeze,

impl<R> RefUnwindSafe for Take<R> where R: RefUnwindSafe,

impl<R> Send for Take<R> where R: Send,

impl<R> Sync for Take<R> where R: Sync,

impl<R> UnsafeUnpin for Take<R> where R: UnsafeUnpin,

impl<R> UnwindSafe for Take<R> where R: UnwindSafe,

Blanket Implementations

impl<R> AsyncBufReadExt for Take<R> where R: AsyncBufRead + ?Sized,

impl<R> AsyncReadExt for Take<R> where R: AsyncRead + ?Sized,

impl<T> Any for Take<R> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Take<R> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Take<R> where T: ?Sized,

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

impl<T> From<T> for Take<R>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for Take<R> where U: From<T>,

fn into(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<U> for Take<R> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Take<R> where U: TryFrom<T>,

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