1

I found myself a bit lost while reading the rust docs, right now I'm unable to find a way to extract A from actix::Addr<A>, I also don't know if that is possible or not.

Rust playground

Important part:

pub struct WebsocketManager {
    pub clients: Vec<Addr<WebsocketActor>>,
}

impl WebsocketManager {
    pub fn send(&self, value: &serde_json::Value, name: &String) {
        if self.clients.is_empty() {
            return;
        }

        let string = serde_json::to_string_pretty(value).unwrap();
        for client in &self.clients {
            //  let actor: WebsocketActor = client.get_websocket_actor();
            //  actor.re.is_match(name) {
            //     client.do_send(StringMessage(string.clone()));
            //  }
        }
    }
}

/// Define http actor
pub struct WebsocketActor {
    server: Arc<Mutex<WebsocketManager>>,
    pub re: Regex,
}
pretzelhammer
  • 13,874
  • 15
  • 47
  • 98
Patrick José Pereira
  • 1,613
  • 2
  • 11
  • 12
  • Not possible in general, but might be in certain cases. What are you trying to do that won't compile? Can you create a [mre]? – trent Aug 30 '20 at 15:04
  • @trentcl Thanks, I have added part of the code and the desired example in the body. It's hard to share the entire thing as a minimal example since it deals with a bunch of different threads, crates and etc. – Patrick José Pereira Aug 30 '20 at 15:41
  • You are possibly looking for recipient: https://docs.rs/actix/0.9.0/actix/struct.Recipient.html – Njuguna Mureithi Sep 02 '20 at 14:27

0 Answers0