pub struct HandlerRegistry { /* private fields */ }Expand description
Registry of command and query handlers.
Game projects register handlers here. Both local and remote adapters
dispatch through this registry. Local dispatch uses TypeId (zero-cost).
Remote dispatch uses the stable protocol name from ProtocolMeta::name().
§Surface independence
The registry is deliberately surface-unaware. Protocol surfaces partition generated artifacts (TypeScript modules, route descriptors) but not handler registration. A handler registered once serves every surface that includes its protocol item. Transport adapters (e.g., an axum router) filter descriptors by surface when mounting routes — the registry itself stays flat.
Implementations§
Source§impl HandlerRegistry
impl HandlerRegistry
Sourcepub fn register_command<C, R, H>(&mut self, handler: H)where
C: Command + ProtocolMeta,
R: Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static,
H: CommandHandler<C, R> + 'static,
pub fn register_command<C, R, H>(&mut self, handler: H)where
C: Command + ProtocolMeta,
R: Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static,
H: CommandHandler<C, R> + 'static,
Register a command handler.
Indexes by both TypeId (for local dispatch) and
ProtocolMeta::name() (for remote dispatch via stable protocol name).
Panics if a handler for this command type or protocol name is already
registered. The name check catches collisions between different Rust
types that share the same ProtocolMeta::name().
Sourcepub fn register_query<Q, R, H>(&mut self, handler: H)where
Q: ProtocolQuery + ProtocolMeta,
R: Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static,
H: QueryHandler<Q, R> + 'static,
pub fn register_query<Q, R, H>(&mut self, handler: H)where
Q: ProtocolQuery + ProtocolMeta,
R: Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static,
H: QueryHandler<Q, R> + 'static,
Register a query handler.
Indexes by both TypeId (for local dispatch) and
ProtocolMeta::name() (for remote dispatch via stable protocol name).
Panics if a handler for this query type or protocol name is already
registered. The name check catches collisions between different Rust
types that share the same ProtocolMeta::name().
Sourcepub fn dispatch_command<C: Command + 'static, R: 'static>(
&self,
cmd: C,
) -> Result<R, String>
pub fn dispatch_command<C: Command + 'static, R: 'static>( &self, cmd: C, ) -> Result<R, String>
Dispatch a command in-process (local adapter path).
Sourcepub fn dispatch_query<Q: ProtocolQuery + 'static, R: 'static>(
&self,
query: Q,
) -> Result<R, String>
pub fn dispatch_query<Q: ProtocolQuery + 'static, R: 'static>( &self, query: Q, ) -> Result<R, String>
Dispatch a query in-process (local adapter path).
Sourcepub fn dispatch_command_json(
&self,
protocol_name: &str,
request_json: &str,
) -> Result<String, String>
pub fn dispatch_command_json( &self, protocol_name: &str, request_json: &str, ) -> Result<String, String>
Dispatch a command via JSON using the stable protocol name.
protocol_name is the value from ProtocolMeta::name() (e.g.,
"SpawnUnit") — the same name that appears in the manifest and
generated descriptors. This is the boundary-safe dispatch path.
Sourcepub fn dispatch_query_json(
&self,
protocol_name: &str,
request_json: &str,
) -> Result<String, String>
pub fn dispatch_query_json( &self, protocol_name: &str, request_json: &str, ) -> Result<String, String>
Dispatch a query via JSON using the stable protocol name.
Sourcepub fn command_count(&self) -> usize
pub fn command_count(&self) -> usize
Returns the number of registered command handlers.
Sourcepub fn query_count(&self) -> usize
pub fn query_count(&self) -> usize
Returns the number of registered query handlers.