Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Standard Library as Architecture

Vector’s runtime graph is built from ordinary collections, ownership, and drop semantics.

HashMap gives identity; IndexMap gives stable fanout order

Topology pieces use HashMap<ComponentKey, ...> to assemble tasks, inputs, outputs, and buffers by component identity. Fanout uses IndexMap so destination membership has stable iteration behavior while still supporting dynamic add, pause, replace, and removal.

Enums make operational policy exhaustive

Transform distinguishes function, synchronous, and task components. ControlMessage distinguishes add, remove, pause, and replace. WhenFull distinguishes block, drop-newest, and overflow. EventStatus distinguishes delivery outcomes.

Every match forces the implementation to state what a new policy variant means at the boundary that executes it.

Option represents lifecycle transitions

A paused fanout destination is an Option<Sender> whose sender has been taken. An optional overflow buffer changes the valid meaning of WhenFull::Overflow. The sink driver stores an optional current batch while alternating between input, readiness, and completion. These are small state machines encoded in data rather than scattered booleans.

Arc carries shared identity backward

Events duplicated by fanout share Arc<EventFinalizer> values. Each branch can update delivery status independently. The source is notified only after the last owner releases the shared finalizer. The shared allocation is not generic “global state”; it represents the identity of one delivery obligation.

Atomics aggregate without a central async task

EventFinalizer stores status in AtomicCell<EventStatus>. Updates combine outcomes monotonically, and Drop records the final value into the shared batch notifier. A one-shot channel wakes the source once all batch owners disappear.

Source: finalization.rs:176

VecDeque makes partial service admission explicit

When Tower becomes unready halfway through a ready chunk, the driver puts the remaining requests back into next_batch. A VecDeque supports taking from the front while preserving the remainder for the next readiness cycle.

Ownership closes the graph

Shutdown starts at sources. When they stop and their senders drop, downstream streams eventually observe closure. Transforms finish and drop their outputs; sinks then drain and finish. Channel ownership encodes much of the shutdown dependency graph without broadcasting a stop message to every stage.