-
When implementing by bot I'm trying to achieve 2 things:
As a result I have the following code: use std::sync::Arc;
use teloxide::{Bot, dptree};
use teloxide::dispatching::{Dispatcher, UpdateFilterExt};
use teloxide::prelude::{Message, Update};
#[tokio::main]
async fn main() {
let input_handler = Arc::new(InputHandler{});
let handler = dptree::entry()
.branch(Update::filter_message().endpoint(handle));
Dispatcher::builder(Bot::from_env(), handler)
.dependencies(dptree::deps![input_handler])
.enable_ctrlc_handler()
.build().dispatch().await;
}
async fn handle(input_handler: Arc<InputHandler>, bot: Bot, msg: Message) -> Result<(), String> {
input_handler.handle(Box::new(CmdImpl{})).await
}
struct InputHandler {
}
trait Cmd {
}
struct CmdImpl {
}
impl Cmd for CmdImpl {
}
impl InputHandler {
async fn handle(&self,
cmd: Box<dyn Cmd>, // this way it does not compile
// cmd: Box<CmdImpl>, // this way it compiles
) -> Result<(), String> {
Ok(())
}
} If I use a trait object as a parameter for
Could anyone please help? |
Beta Was this translation helpful? Give feedback.
Answered by
fertkir
Dec 6, 2023
Replies: 1 comment 2 replies
-
Made it |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
fertkir
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Made it
Box<dyn Input + Send + Sync>
, and it worked