2 ms·
Yeah, callbacks don't really play well with async Rust at the moment, due to those borrow issues. One way to work around it is to define your Bot struct as a St
by Nullabillity 6y ago
Yeah, callbacks don't really play well with async Rust at the moment, due to those borrow issues. One way to work around it is to define your Bot struct as a Stream of Events (an enum for all of your current callbacks).
It's a bit of boilerplate to define, but then your client code can look something like this:
while Some(event) = bot.try_next().await? {
match event {
Event::Speak { text, .. } => {
bot.speak(&text).await?;
}
_ => {}
}
}