pub struct FoldRegistry { /* private fields */ }Expand description
Registry of FoldDispatch adapters keyed by
FoldKind::KIND_ID. The central connection between an
inbound channel message (raw bytes + publisher identity) and
the right fold’s apply path. Construct typed Fold<K>
instances, wrap each in a FoldDispatchAdapter<K>, and
register them here.
Implementations§
Source§impl FoldRegistry
impl FoldRegistry
Sourcepub fn register<K: FoldKind>(
&self,
fold: Arc<Fold<K>>,
) -> Option<Arc<dyn FoldDispatch>>
pub fn register<K: FoldKind>( &self, fold: Arc<Fold<K>>, ) -> Option<Arc<dyn FoldDispatch>>
Register a typed fold under its FoldKind::KIND_ID.
Returns the previously-registered dispatcher under the
same kind if any, so callers that legitimately want to
replace a fold (e.g. swap a new index implementation in
during operator-driven reconfiguration) can drop the
old one cleanly.
Sourcepub fn deregister(&self, kind: u16) -> Option<Arc<dyn FoldDispatch>>
pub fn deregister(&self, kind: u16) -> Option<Arc<dyn FoldDispatch>>
Remove a fold by kind. Returns the dropped dispatcher if one was registered.
Sourcepub fn get(&self, kind: u16) -> Option<Arc<dyn FoldDispatch>>
pub fn get(&self, kind: u16) -> Option<Arc<dyn FoldDispatch>>
Look up a registered dispatcher by kind. Used by tests
and by the channel-integration adapter; the hot path uses
Self::dispatch directly.
Sourcepub fn stats(&self) -> Vec<FoldStats>
pub fn stats(&self) -> Vec<FoldStats>
Aggregate FoldStats across every registered fold.
The operator surface (net fold list, the Deck FOLDS
panel) calls this once per sample tick. Returns in
unspecified order; callers that want a canonical sort sort
themselves.
Sourcepub fn dispatch(
&self,
bytes: &[u8],
publisher: &EntityId,
) -> Result<ApplyOutcome, DispatchError>
pub fn dispatch( &self, bytes: &[u8], publisher: &EntityId, ) -> Result<ApplyOutcome, DispatchError>
Dispatch an inbound wire envelope to the right fold.
The dispatch is two-step:
- A private
peek_kindhelper reads the leadingkind: u16varint to pick the right adapter. This is unavoidable: the per-fold adapter is typed onK::Payload, so we can’t run the full envelope decode until we knowK. - The matched adapter runs the full
SignedAnnouncement::decode_and_verify(which also re-reads thekindfield as part of the struct decode) and thenFold::apply.
The leading varint thus pays for itself twice — once for routing, once during the typed decode — but the cost is ~10 ns of postcard varint work next to a ~50 µs Ed25519 verify on the same envelope. Worth flagging here so future readers don’t chase it as a hot-path concern.
Trait Implementations§
Source§impl Default for FoldRegistry
impl Default for FoldRegistry
Source§impl FoldChannelRouter for FoldRegistry
impl FoldChannelRouter for FoldRegistry
Source§fn try_route(
&self,
publisher: &EntityId,
bytes: &[u8],
) -> Result<ApplyOutcome, DispatchError>
fn try_route( &self, publisher: &EntityId, bytes: &[u8], ) -> Result<ApplyOutcome, DispatchError>
Source§fn stats(&self) -> Vec<FoldStats>
fn stats(&self) -> Vec<FoldStats>
FoldStats for every fold the router
addresses. The operator surface (net fold list, the
Deck FOLDS panel, the Prometheus exporter) calls into
the router-trait object to read stats without knowing
the underlying concrete type. Implementations that
don’t track per-fold stats return an empty Vec.