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
impl DiscardedUsage
Sourcepub fn new() -> Arc<Self> ⓘ
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.
Sourcepub fn slot(self: &Arc<Self>) -> DiscardedUsageSlot
pub fn slot(self: &Arc<Self>) -> DiscardedUsageSlot
A slot that discards one event into this counter.