Skip to main content

TrunkConfig

Struct TrunkConfig 

Source
#[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, }
Available on crate feature 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 — multimux takes its routes from a JSON config, so once these capacities become operator-configurable a stray 0 would take down the server process instead of producing a config error. It also contradicted transmux::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, _> (the ProgressiveDemux shape): correct, but strictly worse here. ProgressiveDemux already returns Result as part of its Stage contract and already has an Error type; TrunkConfig has neither, so this would mean inventing a construction error type and threading ?/unwrap through every construction site to encode one bit of information the type system can carry for free. NonZeroUsize puts the invariant in the signature, where a reader learns it without reading this doc — and, for the JSON-config hazard specifically, a serde deserialize of 0 into a NonZeroUsize field 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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§timed_capacity: NonZeroUsize

Bound, in entry count, on the RetentionClass::Timed ring.

§sparse_capacity: NonZeroUsize

Bound, 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: NonZeroUsize

Bound, 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: NonZeroUsize

Bound, 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: NonZeroUsize

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

Source

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

Source§

fn clone(&self) -> TrunkConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TrunkConfig

Source§

impl Debug for TrunkConfig

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.