pub struct HandlerRegistry { /* private fields */ }Expand description
Registry mapping method names to handlers.
Implementations§
Source§impl HandlerRegistry
impl HandlerRegistry
Sourcepub fn register<F, T, Fut>(
&mut self,
name: &str,
response_type: ResponseType,
handler: F,
)where
F: Fn(T, RequestContext) -> Fut + Send + Sync + 'static,
T: DeserializeOwned + Send + 'static,
Fut: Future<Output = HandlerResult> + Send + 'static,
pub fn register<F, T, Fut>(
&mut self,
name: &str,
response_type: ResponseType,
handler: F,
)where
F: Fn(T, RequestContext) -> Fut + Send + Sync + 'static,
T: DeserializeOwned + Send + 'static,
Fut: Future<Output = HandlerResult> + Send + 'static,
Register a method handler.
§Arguments
name- Method nameresponse_type- Expected response typehandler- Handler function that takes (T, RequestContext) and returns Result<()>
Sourcepub fn register_event(&mut self, name: &str)
pub fn register_event(&mut self, name: &str)
Register an event (no handler, just ID assignment).
Sourcepub fn get_handler(&self, name: &str) -> Option<&dyn Handler>
pub fn get_handler(&self, name: &str) -> Option<&dyn Handler>
Get a handler by method name.
Sourcepub fn get_handler_by_id(&self, id: u16) -> Option<&dyn Handler>
pub fn get_handler_by_id(&self, id: u16) -> Option<&dyn Handler>
Get a handler by method ID.
Sourcepub fn get_method_name(&self, id: u16) -> Option<&str>
pub fn get_method_name(&self, id: u16) -> Option<&str>
Get method name by ID.
Sourcepub fn get_method_id(&self, name: &str) -> Option<u16>
pub fn get_method_id(&self, name: &str) -> Option<u16>
Get method ID by name.
Sourcepub fn get_event_id(&self, name: &str) -> Option<u16>
pub fn get_event_id(&self, name: &str) -> Option<u16>
Get event ID by name.
Sourcepub fn get_response_type(&self, name: &str) -> Option<ResponseType>
pub fn get_response_type(&self, name: &str) -> Option<ResponseType>
Get response type for a method.
Sourcepub fn build_schema(&self) -> InitSchema
pub fn build_schema(&self) -> InitSchema
Build an InitSchema from the registered methods and events.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HandlerRegistry
impl !RefUnwindSafe for HandlerRegistry
impl Send for HandlerRegistry
impl Sync for HandlerRegistry
impl Unpin for HandlerRegistry
impl !UnwindSafe for HandlerRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more