pub struct ApiRouter { /* private fields */ }Expand description
Minimal cloneable router for one command endpoint and multiple query endpoints.
Clones share an immutable endpoint snapshot. Runtime hosts freeze query registration after bootstrap and clone the router before dispatch so no host-state lock is retained while an endpoint executes.
Implementations§
Source§impl ApiRouter
impl ApiRouter
Sourcepub fn set_command_endpoint<E: CommandEndpoint + 'static>(
&mut self,
endpoint: E,
)
pub fn set_command_endpoint<E: CommandEndpoint + 'static>( &mut self, endpoint: E, )
Replaces the command endpoint used by this router.
Sourcepub fn register_query<E: QueryEndpoint + 'static>(
&mut self,
endpoint: E,
) -> RuntimeResult<()>
pub fn register_query<E: QueryEndpoint + 'static>( &mut self, endpoint: E, ) -> RuntimeResult<()>
Registers one uniquely named application query endpoint.
Registration fails after Self::freeze_queries.
Sourcepub fn freeze_queries(&mut self)
pub fn freeze_queries(&mut self)
Freezes application query registration while preserving dispatch.
Sourcepub fn queries_are_frozen(&self) -> bool
pub fn queries_are_frozen(&self) -> bool
Reports whether application query registration is frozen.
Sourcepub fn has_query(&self, name: &QueryName) -> bool
pub fn has_query(&self, name: &QueryName) -> bool
Reports whether a query endpoint is registered.
Sourcepub fn query_names(&self) -> Vec<QueryName>
pub fn query_names(&self) -> Vec<QueryName>
Returns registered query names in deterministic lexical order.
Sourcepub fn query_names_iter(&self) -> impl ExactSizeIterator<Item = &QueryName>
pub fn query_names_iter(&self) -> impl ExactSizeIterator<Item = &QueryName>
Iterates over registered query names without cloning or ordering them.
Callers that expose names externally must impose their required stable order. Validation paths can scan this view without materializing the complete registry.
Sourcepub fn dispatch_query(
&self,
name: &QueryName,
request: ApiRequest,
) -> RuntimeResult<ApiResponse>
pub fn dispatch_query( &self, name: &QueryName, request: ApiRequest, ) -> RuntimeResult<ApiResponse>
Dispatches a request to a named query endpoint.
Sourcepub fn dispatch_command(
&self,
request: ApiRequest,
) -> RuntimeResult<ApiResponse>
pub fn dispatch_command( &self, request: ApiRequest, ) -> RuntimeResult<ApiResponse>
Dispatches a request to the configured command endpoint.