Skip to main content

CountingSource

Struct CountingSource 

Source
pub struct CountingSource<'a, S> { /* private fields */ }
Expand description

A RangedSource adapter that adds each count its source returns to a caller-owned byte counter.

The counter is borrowed, so it keeps the bytes of the successful reads before a failing one and can accumulate across short-lived adapters. It saturates; reaching u64::MAX would take more reads than any input allows.

A count larger than the destination is passed on uncounted, for the caller’s read helper to reject, unless Self::rejecting_overread makes the adapter reject it first.

Implementations§

Source§

impl<'a, S> CountingSource<'a, S>

Source

pub fn new(source: &'a mut S, bytes_read: &'a mut u64) -> Self

Count the bytes source returns into bytes_read.

Source

pub fn rejecting_overread(self, reason: &'static str) -> Self

Reject a count larger than the destination as an invalid-input Error with reason.

Trait Implementations§

Source§

impl<S: RangedSource> RangedSource for CountingSource<'_, S>

Source§

fn size(&self) -> u64

Source§

fn read_at(&mut self, offset: u64, destination: &mut [u8]) -> Result<usize>

Auto Trait Implementations§

§

impl<'a, S> !UnwindSafe for CountingSource<'a, S>

§

impl<'a, S> Freeze for CountingSource<'a, S>

§

impl<'a, S> RefUnwindSafe for CountingSource<'a, S>

§

impl<'a, S> Send for CountingSource<'a, S>
where &'a mut S: Send,

§

impl<'a, S> Sync for CountingSource<'a, S>
where &'a mut S: Sync,

§

impl<'a, S> Unpin for CountingSource<'a, S>

§

impl<'a, S> UnsafeUnpin for CountingSource<'a, S>

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, 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.