#[non_exhaustive]pub struct TrunkConfig {
pub timed_capacity: NonZeroUsize,
pub sparse_capacity: NonZeroUsize,
pub segment_capacity: NonZeroUsize,
pub event_capacity: NonZeroUsize,
pub part_capacity: NonZeroUsize,
}std only.Expand description
Construction parameters for a Trunk.
§Why every capacity is a NonZeroUsize, not a validated usize
A zero capacity is not a value this type rejects — it is a value this type
cannot represent. Every ring in this module evicts its oldest entry
when entries.len() == capacity, so a zero capacity would evict every
entry the instant it was pushed, and a zero waiter cap would make
Trunk::listen incapable of ever registering anybody: not a
configuration, a broken one.
Two weaker designs were considered and rejected:
- Panicking on zero in
Trunk::new(what this type did before): internally consistent, but a library that panics on a value which arrives from a file is a real operational hazard, not a style question —multimuxtakes its routes from a JSON config, so once these capacities become operator-configurable a stray0would take down the server process instead of producing a config error. It also contradictedtransmux::ProgressiveDemux::new’s deliberate panic-to-fallible change, which is exactly the kind of two-crates-apart inconsistency that makes an API feel arbitrary. - A fallible
TrunkConfig::new -> Result<Self, _>(theProgressiveDemuxshape): correct, but strictly worse here.ProgressiveDemuxalready returnsResultas part of itsStagecontract and already has anErrortype;TrunkConfighas neither, so this would mean inventing a construction error type and threading?/unwrapthrough every construction site to encode one bit of information the type system can carry for free.NonZeroUsizeputs the invariant in the signature, where a reader learns it without reading this doc — and, for the JSON-config hazard specifically, aserdedeserialize of0into aNonZeroUsizefield already fails as an ordinary deserialization error at the config boundary, with no hand-written check and no panic.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.timed_capacity: NonZeroUsizeBound, in entry count, on the RetentionClass::Timed ring.
sparse_capacity: NonZeroUsizeBound, in entry count, on the RetentionClass::Sparse ring —
independent of timed_capacity; see RetentionClass::Sparse for
why that independence is the entire point of the retention rule.
segment_capacity: NonZeroUsizeBound, in entry count, on the segment log. Also the bound a
pinning SegmentCursor’s retention is measured against — see
The DVR contradiction
for why there is deliberately no second, independent “pin depth”
knob.
event_capacity: NonZeroUsizeBound, in entry count, on the event log — and on its segment
boundary table (EventLog::segment_starts). See
The event log
for why a segment-relative event’s target boundary shares this one
knob rather than getting a second, independently-tuned one —
exactly TrunkConfig::segment_capacity’s “no second capacity
knob” precedent for pinning.
part_capacity: NonZeroUsizeBound, in entry count, on the live-part log (step 3b-iv) — and
on how many concurrent Trunk::listen registrations this trunk
will honor at once. See
The live-part log
for why a part-of-the-open-segment shares this one knob for both
jobs, rather than getting a second, independently-tuned “how many
waiters” setting — the third instance of this file’s “no second
capacity knob” precedent (after TrunkConfig::segment_capacity’s
pin reuse and TrunkConfig::event_capacity’s segment_starts
reuse).
Implementations§
Source§impl TrunkConfig
impl TrunkConfig
Sourcepub fn new(
timed_capacity: NonZeroUsize,
sparse_capacity: NonZeroUsize,
segment_capacity: NonZeroUsize,
event_capacity: NonZeroUsize,
part_capacity: NonZeroUsize,
) -> Self
pub fn new( timed_capacity: NonZeroUsize, sparse_capacity: NonZeroUsize, segment_capacity: NonZeroUsize, event_capacity: NonZeroUsize, part_capacity: NonZeroUsize, ) -> Self
Build a config with all five ring capacities. Nothing is validated
here, and nothing needs to be: NonZeroUsize makes the only
invalid value unrepresentable rather than merely rejected — see
this type’s own docs
for why that beats both the panic this replaced and a fallible
constructor.
Trait Implementations§
Source§impl Clone for TrunkConfig
impl Clone for TrunkConfig
Source§fn clone(&self) -> TrunkConfig
fn clone(&self) -> TrunkConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more