pub struct Router { /* private fields */ }Expand description
Routes events to registered agents based on event type.
The Router maintains a mapping of event TypeIds to vectors of agents that should process those events. Multiple agents can be registered for the same event type.
§Examples
ⓘ
use mojentic::router::Router;
let mut router = Router::new();
router.add_route::<MyEvent>(my_agent);Implementations§
Source§impl Router
impl Router
Sourcepub fn add_route<T: 'static>(&mut self, agent: Arc<dyn BaseAsyncAgent>)
pub fn add_route<T: 'static>(&mut self, agent: Arc<dyn BaseAsyncAgent>)
Add a route mapping an event type to an agent
§Arguments
agent- The agent to handle events of type T
Sourcepub fn get_agents(&self, type_id: TypeId) -> Vec<Arc<dyn BaseAsyncAgent>>
pub fn get_agents(&self, type_id: TypeId) -> Vec<Arc<dyn BaseAsyncAgent>>
Get all agents registered for a specific event type
§Arguments
type_id- The TypeId of the event type
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Router
impl !RefUnwindSafe for Router
impl Send for Router
impl Sync for Router
impl Unpin for Router
impl !UnwindSafe for Router
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