pub struct HandlerRegistry { /* private fields */ }Expand description
Registry of event handlers
Implementations§
Source§impl HandlerRegistry
impl HandlerRegistry
Sourcepub fn register_simple<F>(&self, name: &str, handler: F)
pub fn register_simple<F>(&self, name: &str, handler: F)
Register a simple handler
Sourcepub fn register_with_value<F>(&self, name: &str, handler: F)
pub fn register_with_value<F>(&self, name: &str, handler: F)
Register a handler with a value parameter
Sourcepub fn register_with_command<F>(&self, name: &str, handler: F)
pub fn register_with_command<F>(&self, name: &str, handler: F)
Register a handler that returns a command
Sourcepub fn get(&self, name: &str) -> Option<HandlerEntry>
pub fn get(&self, name: &str) -> Option<HandlerEntry>
Look up a handler by name
Sourcepub fn dispatch(
&self,
handler_name: &str,
model: &mut dyn Any,
value: Option<String>,
)
pub fn dispatch( &self, handler_name: &str, model: &mut dyn Any, value: Option<String>, )
Dispatches a handler by name, executing it with the provided model and optional value.
This is a convenience method that combines get() and handler invocation.
§Arguments
handler_name- Name of the handler to dispatchmodel- Mutable reference to the model (as&mut dyn Any)value- Optional string value passed to WithValue handlers
§Example
ⓘ
use dampen_core::HandlerRegistry;
let registry = HandlerRegistry::new();
registry.register_simple("greet", |model| {
let model = model.downcast_mut::<MyModel>().unwrap();
model.count += 1;
});
let model = &mut MyModel { count: 0 } as &mut dyn std::any::Any;
registry.dispatch("greet", model, None);Trait Implementations§
Source§impl Clone for HandlerRegistry
impl Clone for HandlerRegistry
Source§fn clone(&self) -> HandlerRegistry
fn clone(&self) -> HandlerRegistry
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HandlerRegistry
impl Debug for HandlerRegistry
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