//! See how we can have a collection of addresses to differnt actors. In this example //! we want to store several actors that all accept the same message type. // use { thespis :: { * } , thespis_impl :: { * } , async_executors :: { AsyncStd } , std :: { error::Error } , }; #[ derive( Actor ) ] struct Actor1; #[ derive( Actor ) ] struct Actor2; struct Ping; impl Message for Ping { type Return = (); } impl Handler< Ping > for Actor1 { #[async_fn] fn handle( &mut self, _msg: Ping ) {} } impl Handler< Ping > for Actor2 { #[async_fn] fn handle( &mut self, _msg: Ping ) {} } #[async_std::main] // async fn main() -> Result< (), Box > { // As you can see, the addresses are generic over the actor type. // So we can't just store them in a collection. // let addr1: Addr = Addr::builder( "actor 1" ).spawn( Actor1, &AsyncStd )?; let addr2: Addr = Addr::builder( "actor 2" ).spawn( Actor2, &AsyncStd )?; // pub type BoxAddress = Box< dyn Address + Send + Unpin >; // Type can be elided here. It's just there for illustrative purposes. // // Obviously if we have a known number of types, we could use an enum. If // not, we can use a dynamic type. // let col: Vec> = vec! [ addr1.clone_box() , addr2.clone_box() , ]; for mut addr in col { addr.send( Ping ).await?; } Ok(()) }