pub struct QueryHandlerRegistry { /* private fields */ }
Expand description
The QueryHandlerRegistry
struct manages the registration and retrieval of query handlers.
This registry maintains a mapping between query types and their corresponding handlers.
It is used internally by the QueryBus
to dispatch queries to the correct handler.
Implementations§
Source§impl QueryHandlerRegistry
QueryHandlerRegistry
implementation.
impl QueryHandlerRegistry
QueryHandlerRegistry
implementation.
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new, empty QueryHandlerRegistry
.
§Example
use discern::registry::QueryHandlerRegistry;
let registry = QueryHandlerRegistry::new();
Sourcepub fn register<Q: Query>(&mut self, handler: impl QueryHandler<Q> + 'static)
pub fn register<Q: Query>(&mut self, handler: impl QueryHandler<Q> + 'static)
Registers a query handler for a specific query type.
§Arguments
handler
- The handler to be registered for the query typeQ
.
This method associates a query type with its corresponding handler.
When a query of type Q
is dispatched, the QueryBus
will use the handler registered here.
§Example
let mut registry = QueryHandlerRegistry::new();
registry.register(MyQueryHandler);
Sourcepub fn get_handler<Q: Query>(&self) -> Option<Box<dyn QueryHandler<Q>>>
pub fn get_handler<Q: Query>(&self) -> Option<Box<dyn QueryHandler<Q>>>
Retrieves the query handler for a specific query type.
§Returns
An Option
containing the query handler if found, or None
if no handler is registered for the query type Q
.
§Example
let mut registry = QueryHandlerRegistry::new();
registry.register(MyQueryHandler);
let handler = registry.get_handler::<MyQuery>();
assert!(handler.is_some());
Trait Implementations§
Source§impl Debug for QueryHandlerRegistry
Debug implementation for QueryHandlerRegistry
impl Debug for QueryHandlerRegistry
Debug implementation for QueryHandlerRegistry
Source§impl Default for QueryHandlerRegistry
impl Default for QueryHandlerRegistry
Source§fn default() -> QueryHandlerRegistry
fn default() -> QueryHandlerRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for QueryHandlerRegistry
impl !RefUnwindSafe for QueryHandlerRegistry
impl Send for QueryHandlerRegistry
impl Sync for QueryHandlerRegistry
impl Unpin for QueryHandlerRegistry
impl !UnwindSafe for QueryHandlerRegistry
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