Skip to main content

DiscardedUsage

Struct DiscardedUsage 

Source
pub struct DiscardedUsage { /* private fields */ }
Expand description

A UsageSlot that discards the event and counts it.

The reference implementation for an integration that has not reached usage export yet, in the same spirit as NoGate for CapacityGate: it lets an embedder adopt admission one stage at a time instead of taking the client runtime and a background writer purely to satisfy a type.

It counts what it discarded, deliberately. A silently dropping slot makes “usage is not wired up” indistinguishable from “no usage happened”, and those are very different operational stories — one of them means an integration is admitting billable work and losing the record of it.

Not for production billing. Discarded events are not recoverable; use the batching writer once usage must be durable.

Deliberately no Default. A zero-valued counter would make Default::default() and new() the same value, leaving a mutant no test can distinguish; an equivalent mutant is a design smell rather than a coverage gap. new returning Arc<Self> also keeps clippy’s new_without_default inapplicable, so the two gates agree rather than pulling opposite ways.

let discarded = DiscardedUsage::new();
// hand `discarded.slot()` to `admit`; assert on the count later
assert_eq!(discarded.count(), 0);

Implementations§

Source§

impl DiscardedUsage

Source

pub fn new() -> Arc<Self> ⓘ

A shared counter, ready to hand out slots.

Returns Arc<Self> because that is the only useful form: Self::slot needs one, and a bare DiscardedUsage can do nothing. Making the reachable shape the only constructible one removes a step an embedder would otherwise have to know to take.

Source

pub fn slot(self: &Arc<Self>) -> DiscardedUsageSlot

A slot that discards one event into this counter.

Source

pub fn count(&self) -> u64

How many events have been discarded.

Trait Implementations§

Source§

impl Debug for DiscardedUsage

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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