pub struct Meter { /* private fields */ }Expand description
A running byte budget for one answer.
Separate from read because a streamed answer is consumed event by event
by a decoder that has to see each chunk — there is no whole body to hand
back. The same ceiling applies to the same bytes; only the consumer differs.
What it bounds on that path is the number of events, not their size: a per-event ceiling stops the unterminated line and lets well-formed hundred- byte deltas accumulate until the process dies.
Implementations§
Source§impl Meter
impl Meter
pub const fn new(limit: usize) -> Self
Sourcepub fn charge(&mut self, bytes: usize) -> Result<(), IntakeError>
pub fn charge(&mut self, bytes: usize) -> Result<(), IntakeError>
Charge a chunk against the budget.
§Errors
IntakeError::Exceeded once the answer has cost more than the budget.
Checked before the caller keeps the chunk, so the ceiling bounds what
is held rather than what has already been held.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Meter
impl RefUnwindSafe for Meter
impl Send for Meter
impl Sync for Meter
impl Unpin for Meter
impl UnsafeUnpin for Meter
impl UnwindSafe for Meter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.