Advertisement
Guest User

Untitled

a guest
Nov 7th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.86 KB | None | 0 0
  1. struct Hub {
  2.     rooms: Vec<String>,
  3. }
  4.  
  5. impl Actor for Hub {
  6.     type Context = Context<Self>;
  7. }
  8.  
  9. impl Hub {
  10.     pub fn new() -> Hub {
  11.         Hub {
  12.             rooms: vec![]
  13.         }
  14.     }
  15.  
  16.     fn get_unique_id(&self) -> String {
  17.         String::from("unique_id")
  18.     }
  19. }
  20.  
  21.  
  22. struct CreateRoom;
  23. impl Message for CreateRoom {
  24.     type Result = String;
  25. }
  26.  
  27. impl Handler<CreateRoom> for Hub {
  28.     type Result = String;
  29.  
  30.     fn handle(&mut self, msg: CreateRoom, ctx: &mut Context<Self>) -> Self::Result {
  31.         let id = self.get_unique_id();
  32.         self.rooms.push(id.clone());
  33.         id
  34.     }
  35. }
  36.  
  37.  
  38. //External wrapper
  39. struct HubWrapper(Addr<Hub>);
  40. impl HubWrapper {
  41.     pub fn add(&self) -> String {
  42.         let res = self.0.send(CreateRoom);
  43.  
  44.         //how can I exec the future and return here the ID of this new room?
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement