Skip to main content

FoldRegistry

Struct FoldRegistry 

Source
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

Source

pub fn new() -> Self

Construct an empty registry.

Source

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.

Source

pub fn deregister(&self, kind: u16) -> Option<Arc<dyn FoldDispatch>>

Remove a fold by kind. Returns the dropped dispatcher if one was registered.

Source

pub fn len(&self) -> usize

Number of registered folds.

Source

pub fn is_empty(&self) -> bool

Whether the registry has no folds registered.

Source

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.

Source

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.

Source

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:

  1. A private peek_kind helper reads the leading kind: u16 varint to pick the right adapter. This is unavoidable: the per-fold adapter is typed on K::Payload, so we can’t run the full envelope decode until we know K.
  2. The matched adapter runs the full SignedAnnouncement::decode_and_verify (which also re-reads the kind field as part of the struct decode) and then Fold::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

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl FoldChannelRouter for FoldRegistry

Source§

fn try_route( &self, publisher: &EntityId, bytes: &[u8], ) -> Result<ApplyOutcome, DispatchError>

Route one wire envelope to the right fold. Errors are surfaced so the mesh dispatch arm can log + bump metrics; the mesh never lets a router error escape into the rest of the inbound pipeline (single-packet failures must not take down the dispatch loop).
Source§

fn stats(&self) -> Vec<FoldStats>

Aggregated 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.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more