pub struct LengthLimit<T> { /* private fields */ }
Expand description

§AsyncRead length limiter

The number of bytes will never be more than the provided byte limit. If the byte limit is exactly the length of the contained AsyncRead, it is considered an error.

§Errors

This will return an error if the underlying AsyncRead does so or if the read length meets (or would exceed) the provided length limit. The returned std::io::Error will have an error kind of ErrorKind::InvalidData and a contained error of LengthLimitExceeded.

Implementations§

source§

impl<T> LengthLimit<T>
where T: AsyncRead,

source

pub fn new(reader: T, max_bytes: usize) -> Self

Constructs a new LengthLimit with provided AsyncRead reader and max_bytes byte length

source

pub fn bytes_remaining(&self) -> usize

Returns the number of additional bytes before the limit is reached

source

pub fn into_inner(self) -> T

Unwraps the contained AsyncRead, allowing it to be read to completion. bytes remaining data are discarded

Trait Implementations§

source§

impl<T> AsRef<T> for LengthLimit<T>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T: AsyncRead> AsyncRead for LengthLimit<T>

source§

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

Attempt to read from the AsyncRead into buf. Read more
source§

fn poll_read_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more
source§

impl<T: Clone> Clone for LengthLimit<T>

source§

fn clone(&self) -> LengthLimit<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for LengthLimit<T>

source§

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

Formats the value using the given formatter. Read more
source§

impl<T: Copy> Copy for LengthLimit<T>

source§

impl<'__pin, T> Unpin for LengthLimit<T>
where __Origin<'__pin, T>: Unpin,

Auto Trait Implementations§

§

impl<T> Freeze for LengthLimit<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for LengthLimit<T>
where T: RefUnwindSafe,

§

impl<T> Send for LengthLimit<T>
where T: Send,

§

impl<T> Sync for LengthLimit<T>
where T: Sync,

§

impl<T> UnwindSafe for LengthLimit<T>
where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>
where Self: Unpin,

Reads some bytes from the byte stream. Read more
source§

fn read_vectored<'a>( &'a mut self, bufs: &'a mut [IoSliceMut<'a>] ) -> ReadVectoredFuture<'a, Self>
where Self: Unpin,

Like read(), except it reads into a slice of buffers. Read more
source§

fn read_to_end<'a>( &'a mut self, buf: &'a mut Vec<u8> ) -> ReadToEndFuture<'a, Self>
where Self: Unpin,

Reads the entire contents and appends them to a Vec. Read more
source§

fn read_to_string<'a>( &'a mut self, buf: &'a mut String ) -> ReadToStringFuture<'a, Self>
where Self: Unpin,

Reads the entire contents and appends them to a String. Read more
source§

fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>
where Self: Unpin,

Reads the exact number of bytes required to fill buf. Read more
source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Converts this AsyncRead into a Stream of bytes. Read more
source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: AsyncRead, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
source§

fn boxed_reader<'a>(self) -> Pin<Box<dyn AsyncRead + Send + 'a>>
where Self: Sized + Send + 'a,

Boxes the reader and changes its type to dyn AsyncRead + Send + 'a. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> LengthLimitExt for T
where T: AsyncRead + Unpin,

source§

fn limit_bytes(self, max_bytes: usize) -> LengthLimit<Self>

Applies a LengthLimit to self with an exclusive maxiumum of max_bytes bytes
source§

fn limit_kb(self, max_kb: usize) -> LengthLimit<Self>

Applies a LengthLimit to self with an exclusive maxiumum of max_kb kilobytes (defined as 1024 bytes)
source§

fn limit_mb(self, max_mb: usize) -> LengthLimit<Self>

Applies a LengthLimit to self with an exclusive maxiumum of max_mb megabytes (defined as 1024 kilobytes, or 1,048,576 bytes)
source§

fn limit_gb(self, max_gb: usize) -> LengthLimit<Self>

Applies a LengthLimit to self with an exclusive maxiumum of max_gb kilobytes (defined as 1024 megabytes, or 1,073,741,824 bytes)
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

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

Performs the conversion.