Skip to main content

HandlerRegistry

Struct HandlerRegistry 

Source
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

Source

pub fn new() -> Self

Create an empty registry.

Source

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().

Source

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().

Source

pub fn dispatch_command<C: Command + 'static, R: 'static>( &self, cmd: C, ) -> Result<R, String>

Dispatch a command in-process (local adapter path).

Source

pub fn dispatch_query<Q: ProtocolQuery + 'static, R: 'static>( &self, query: Q, ) -> Result<R, String>

Dispatch a query in-process (local adapter path).

Source

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.

Source

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.

Source

pub fn command_count(&self) -> usize

Returns the number of registered command handlers.

Source

pub fn query_count(&self) -> usize

Returns the number of registered query handlers.

Trait Implementations§

Source§

impl Default for HandlerRegistry

Source§

fn default() -> Self

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

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.