Limit

Struct Limit 

Source
pub struct Limit<'a, R: Reader + ?Sized> { /* private fields */ }
Expand description

Wraps a reader and limits the amount of data that can be read from it

This can be used for applying back pressure to the reader with flow control.

Implementations§

Source§

impl<'a, R: Reader + ?Sized> Limit<'a, R>

Source

pub fn new(reader: &'a mut R, max_buffered_len: usize) -> Self

Trait Implementations§

Source§

impl<R: Reader + ?Sized> Reader for Limit<'_, R>

Source§

fn current_offset(&self) -> VarInt

Returns the currently read offset for the stream
Source§

fn final_offset(&self) -> Option<VarInt>

Returns the final offset for the stream
Source§

fn has_buffered_fin(&self) -> bool

Returns true if the reader has the final offset buffered
Source§

fn is_consumed(&self) -> bool

Returns true if the reader is finished producing data
Source§

fn skip_until(&mut self, offset: VarInt) -> Result<(), Self::Error>

Skips the data in the reader until offset is reached, or the reader storage is exhausted.
Source§

fn with_max_data(&mut self, max_data: VarInt) -> Limit<'_, Self>

Limits the maximum offset that the caller can read from the reader
Source§

fn with_read_limit(&mut self, max_buffered_len: usize) -> Limit<'_, Self>

Limits the maximum amount of data that the caller can read from the reader
Source§

fn with_empty_buffer(&self) -> Empty<'_, Self>

Return an empty view onto the reader, with no change in current offset
Source§

fn with_checks(&mut self) -> Checked<'_, Self>

Enables checking the reader for correctness invariants Read more
Source§

impl<R: Reader + ?Sized> Storage for Limit<'_, R>

Source§

type Error = <R as Storage>::Error

Source§

fn buffered_len(&self) -> usize

Returns the length of the chunk
Source§

fn read_chunk(&mut self, watermark: usize) -> Result<Chunk<'_>, Self::Error>

Reads the current contiguous chunk
Source§

fn partial_copy_into<Dest>( &mut self, dest: &mut Dest, ) -> Result<Chunk<'_>, Self::Error>
where Dest: Storage + ?Sized,

Copies the reader into dest, with a trailing chunk of bytes. Read more
Source§

fn copy_into<Dest>(&mut self, dest: &mut Dest) -> Result<(), Self::Error>
where Dest: Storage + ?Sized,

Copies the reader into dest. Read more
Source§

fn buffer_is_empty(&self) -> bool

Returns if the chunk is empty
Source§

fn full_copy(&mut self) -> FullCopy<'_, Self>

Forces the entire reader to be copied, even when calling partial_copy_into. Read more
Source§

fn track_read(&mut self) -> Tracked<'_, Self>

Tracks the number of bytes read from the storage

Auto Trait Implementations§

§

impl<'a, R> Freeze for Limit<'a, R>
where R: ?Sized,

§

impl<'a, R> RefUnwindSafe for Limit<'a, R>
where R: RefUnwindSafe + ?Sized,

§

impl<'a, R> Send for Limit<'a, R>
where R: Send + ?Sized,

§

impl<'a, R> Sync for Limit<'a, R>
where R: Sync + ?Sized,

§

impl<'a, R> Unpin for Limit<'a, R>
where R: ?Sized,

§

impl<'a, R> !UnwindSafe for Limit<'a, R>

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<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> Infallible for T
where T: Storage<Error = Infallible> + ?Sized,

Source§

fn infallible_read_chunk(&mut self, watermark: usize) -> Chunk<'_>

Source§

fn infallible_partial_copy_into<Dest>(&mut self, dest: &mut Dest) -> Chunk<'_>
where Dest: Storage + ?Sized,

Source§

fn infallible_copy_into<Dest>(&mut self, dest: &mut Dest)
where Dest: Storage + ?Sized,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.
Source§

impl<T, U> Upcast<T> for U
where T: UpcastFrom<U>,

Source§

fn upcast(self) -> T

Source§

impl<T, B> UpcastFrom<Counter<T, B>> for T

Source§

fn upcast_from(value: Counter<T, B>) -> T