Skip to main content

Handler

Struct Handler 

Source
pub struct Handler<'a, Output, Descr = Unspecified> { /* private fields */ }
Expand description

An instance that receives an input and decides whether to break a chain or pass the value further.

In order to create this structure, you can use the predefined functions from crate.

§The difference between chaining and branching

Handlers can be chained via Handler::chain and branched via Handler::branch. To understand the difference between the two, consider the following examples: a.chain(b).c and a.branch(b).c.

In a.chain(b).c, the handler a is given the rest of the handler chain, b and c; if a decides to pass the value further, it invokes b. Then, if b decides to pass the value further, it invokes c. Thus, the handler chain is linear.

In a.branch(b).c, if a decides to pass the value further, it invokes b. But since b is “branched”, it receives an empty chain, so it cannot invoke c. Instead, if b decides to continue execution (ControlFlow::Continue), a invokes c; otherwise (ControlFlow::Break), the process is terminated. The handler chain is nested.

To sum up, chaining looks like this:

a -> b -> c

And branching looks like this:

a -> b
  -> c

This is very crucial when b is a filter: if it is chained, it decides whether or not to call c, but when it is branched, whether c is called depends solely on a.

Implementations§

Source§

impl<'a, Output, Descr> Handler<'a, Output, Descr>
where Output: 'a, Descr: HandlerDescription,

Source

pub fn chain( self, next: Handler<'a, Output, Descr>, ) -> Handler<'a, Output, Descr>

Chain two handlers to form a chain of responsibility.

Chaining is different from branching. See “The difference between chaining and branching”.

This method makes use of HandlerSignature (stored in every handler) to perform run-time type inference of the resulting handler signature; this information is used by crate::type_check to make sure that all required types are provided before execution.

§Examples
use dptree::prelude::*;

let handler: Handler<_> =
    dptree::filter(|x: i32| x > 0).chain(dptree::endpoint(|| async { "done" }));

assert_eq!(handler.dispatch(dptree::deps![10]).await, ControlFlow::Break("done"));
assert_eq!(
    handler.dispatch(dptree::deps![-10]).await,
    ControlFlow::Continue(dptree::deps![-10])
);
Source

pub fn branch( self, next: Handler<'a, Output, Descr>, ) -> Handler<'a, Output, Descr>
where Output: Send,

Chain two handlers to make a tree of responsibility.

Chaining is different from branching. See “The difference between chaining and branching”.

This method makes use of HandlerSignature (stored in every handler) to perform run-time type inference of the resulting handler signature; this information is used by crate::type_check to make sure that all required types are provided before execution.

§Examples
use dptree::prelude::*;


#[derive(Debug, PartialEq)]
enum Output {
    Five,
    One,
    GT,
}

let dispatcher: Handler<_> = dptree::entry()
    .branch(dptree::filter(|num: i32| num == 5).endpoint(|| async move { Output::Five }))
    .branch(dptree::filter(|num: i32| num == 1).endpoint(|| async move { Output::One }))
    .branch(dptree::filter(|num: i32| num > 2).endpoint(|| async move { Output::GT }));

assert_eq!(dispatcher.dispatch(dptree::deps![5]).await, ControlFlow::Break(Output::Five));
assert_eq!(dispatcher.dispatch(dptree::deps![1]).await, ControlFlow::Break(Output::One));
assert_eq!(dispatcher.dispatch(dptree::deps![3]).await, ControlFlow::Break(Output::GT));
assert_eq!(
    dispatcher.dispatch(dptree::deps![0]).await,
    ControlFlow::Continue(dptree::deps![0])
);
Examples found in repository?
examples/buttons.rs (line 31)
24async fn main() -> Result<(), Box<dyn Error>> {
25    pretty_env_logger::init();
26    log::info!("Starting buttons bot...");
27
28    let bot = Bot::from_env();
29
30    let handler = dptree::entry()
31        .branch(Update::filter_message().endpoint(message_handler))
32        .branch(Update::filter_callback_query().endpoint(callback_handler))
33        .branch(Update::filter_inline_query().endpoint(inline_query_handler));
34
35    Dispatcher::builder(bot, handler).enable_ctrlc_handler().build().dispatch().await;
36    Ok(())
37}
More examples
Hide additional examples
examples/deep_linking.rs (lines 47-51)
40async fn main() {
41    pretty_env_logger::init();
42    log::info!("Starting deep linking bot...");
43
44    let bot = Bot::from_env();
45
46    let handler = dialogue::enter::<Update, InMemStorage<State>, State, _>()
47        .branch(
48            Update::filter_message()
49                .filter_command::<StartCommand>()
50                .branch(case![StartCommand::Start(start)].endpoint(start)),
51        )
52        .branch(
53            Update::filter_message()
54                .branch(case![State::WriteToSomeone { id }].endpoint(send_message)),
55        );
56
57    Dispatcher::builder(bot, handler)
58        .dependencies(deps![InMemStorage::<State>::new()])
59        .enable_ctrlc_handler()
60        .build()
61        .dispatch()
62        .await;
63}
examples/dialogue.rs (line 46)
36async fn main() {
37    pretty_env_logger::init();
38    log::info!("Starting dialogue bot...");
39
40    let bot = Bot::from_env();
41
42    Dispatcher::builder(
43        bot,
44        Update::filter_message()
45            .enter_dialogue::<Message, InMemStorage<State>, State>()
46            .branch(dptree::case![State::Start].endpoint(start))
47            .branch(dptree::case![State::ReceiveFullName].endpoint(receive_full_name))
48            .branch(dptree::case![State::ReceiveAge { full_name }].endpoint(receive_age))
49            .branch(
50                dptree::case![State::ReceiveLocation { full_name, age }].endpoint(receive_location),
51            ),
52    )
53    .dependencies(dptree::deps![InMemStorage::<State>::new()])
54    .enable_ctrlc_handler()
55    .build()
56    .dispatch()
57    .await;
58}
examples/purchase.rs (lines 66-70)
62fn schema() -> UpdateHandler<Box<dyn std::error::Error + Send + Sync + 'static>> {
63    use dptree::case;
64
65    let command_handler = ronami::filter_command::<Command, _>()
66        .branch(
67            case![State::Start]
68                .branch(case![Command::Help].endpoint(help))
69                .branch(case![Command::Start].endpoint(start)),
70        )
71        .branch(case![Command::Cancel].endpoint(cancel));
72
73    let message_handler = Update::filter_message()
74        .branch(command_handler)
75        .branch(case![State::ReceiveFullName].endpoint(receive_full_name))
76        .branch(dptree::endpoint(invalid_state));
77
78    let callback_query_handler = Update::filter_callback_query().branch(
79        case![State::ReceiveProductChoice { full_name }].endpoint(receive_product_selection),
80    );
81
82    dialogue::enter::<Update, InMemStorage<State>, State, _>()
83        .branch(message_handler)
84        .branch(callback_query_handler)
85}
examples/db_remember.rs (line 49)
35async fn main() {
36    pretty_env_logger::init();
37    log::info!("Starting DB remember bot...");
38
39    let bot = Bot::from_env();
40
41    let storage: MyStorage = if std::env::var("DB_REMEMBER_REDIS").is_ok() {
42        RedisStorage::open("redis://127.0.0.1:6379", Bincode).await.unwrap().erase()
43    } else {
44        SqliteStorage::open("db.sqlite", Json).await.unwrap().erase()
45    };
46
47    let handler = Update::filter_message()
48        .enter_dialogue::<Message, ErasedStorage<State>, State>()
49        .branch(dptree::case![State::Start].endpoint(start))
50        .branch(
51            dptree::case![State::GotNumber(n)]
52                .branch(dptree::entry().filter_command::<Command>().endpoint(got_number))
53                .branch(dptree::endpoint(invalid_command)),
54        );
55
56    Dispatcher::builder(bot, handler)
57        .dependencies(dptree::deps![storage])
58        .enable_ctrlc_handler()
59        .build()
60        .dispatch()
61        .await;
62}
examples/chat_member_updates.rs (lines 28-42)
16async fn main() -> ResponseResult<()> {
17    pretty_env_logger::init();
18
19    // We specify default parse mode to be `Html`, so that later we can use
20    // `html::user_mention`
21    let bot = ronami::Bot::from_env().parse_mode(ParseMode::Html);
22
23    // Create a handler for our bot, that will process updates from Telegram
24    let handler = dptree::entry()
25        .inspect(|u: Update| {
26            eprintln!("{u:#?}"); // Print the update to the console with inspect
27        })
28        .branch(
29            Update::filter_chat_member()
30                .branch(
31                    dptree::filter(|m: ChatMemberUpdated| {
32                        m.old_chat_member.is_left() && m.new_chat_member.is_present()
33                    })
34                    .endpoint(new_chat_member),
35                )
36                .branch(
37                    dptree::filter(|m: ChatMemberUpdated| {
38                        m.old_chat_member.is_present() && m.new_chat_member.is_left()
39                    })
40                    .endpoint(left_chat_member),
41                ),
42        );
43
44    // Create a dispatcher for our bot
45    Dispatcher::builder(bot, handler).enable_ctrlc_handler().build().dispatch().await;
46
47    Ok(())
48}
Source

pub async fn execute<Cont, ContFut>( self, input: DependencyMap, cont: Cont, ) -> ControlFlow<Output, DependencyMap>
where Cont: FnOnce(DependencyMap) -> ContFut + Send + Sync + 'a, ContFut: Future<Output = ControlFlow<Output, DependencyMap>> + Send + 'a,

Executes this handler with a continuation.

Usually, you do not want to call this method by yourself, if you do not write your own handler implementation. If you wish to execute handler without a continuation, take a look at the Handler::dispatch method.

NOTE: If you are using DependencyMap, you should first call crate::type_check to type-check your handler against a container; otherwise, type checking will be delayed until the actual execution, which can make things harder to debug.

§Examples
use dptree::prelude::*;

let handler: Handler<_> = dptree::filter(|x: i32| x > 0);

let output = handler.execute(dptree::deps![10], |_| async { ControlFlow::Break("done") }).await;
assert_eq!(output, ControlFlow::Break("done"));
Source

pub async fn dispatch( &self, input: DependencyMap, ) -> ControlFlow<Output, DependencyMap>

Executes this handler.

Returns ControlFlow::Break when executed successfully, ControlFlow::Continue otherwise.

NOTE: If you are using DependencyMap, you should first call crate::type_check to type-check your handler against a container; otherwise, type checking will be delayed until the actual execution, which can make things harder to debug.

Source

pub fn description(&self) -> &Descr

Returns the set of updates that can be processed by this handler.

Source

pub fn sig(&self) -> &HandlerSignature

Returns this handler’s run-time type signature.

Source§

impl<'a, Output, Descr> Handler<'a, Output, Descr>
where Output: 'a, Descr: HandlerDescription,

Source

pub fn filter<Pred, FnArgs>(self, pred: Pred) -> Handler<'a, Output, Descr>
where Asyncify<Pred>: Injectable<bool, FnArgs> + Send + Sync + 'a,

Chain this handler with the filter predicate pred.

Examples found in repository?
examples/middlewares_fallible.rs (lines 19-28)
6async fn main() {
7    pretty_env_logger::init();
8    log::info!("Starting middlewares_fallible bot...");
9
10    let bot = Bot::from_env();
11
12    let handler = Update::filter_message()
13        // Executes before the endpoint.
14        .inspect(|msg: Message| println!("Before (message #{}).", msg.id))
15        // Our "endpoint".
16        .map_async(my_endpoint)
17        // Executes after the endpoint. If the endpoint failed, print an error message and stop
18        // execution; if not, continue.
19        .filter(|result: HandlerResult, msg: Message| {
20            println!("In-between (message #{}).", msg.id);
21            match result {
22                Ok(()) => true,
23                Err(err) => {
24                    eprintln!("Our endpoint failed: {err}");
25                    false
26                }
27            }
28        })
29        // Executes only if the endpoint succeeded.
30        .endpoint(|msg: Message| async move {
31            println!("After (message #{}).", msg.id);
32            HandlerResult::Ok(())
33        });
34
35    Dispatcher::builder(bot, handler).enable_ctrlc_handler().build().dispatch().await;
36}
Source

pub fn filter_async<Pred, FnArgs>( self, pred: Pred, ) -> Handler<'a, Output, Descr>
where Pred: Injectable<bool, FnArgs> + Send + Sync + 'a,

Chain this handler with the async filter predicate pred.

Source

pub fn filter_map<Proj, NewType, Args>( self, proj: Proj, ) -> Handler<'a, Output, Descr>
where Asyncify<Proj>: Injectable<Option<NewType>, Args> + Send + Sync + 'a, NewType: Send + Sync + 'static,

Chain this handler with the filter projection proj.

Source

pub fn filter_map_async<Proj, NewType, Args>( self, proj: Proj, ) -> Handler<'a, Output, Descr>
where Proj: Injectable<Option<NewType>, Args> + Send + Sync + 'a, NewType: Send + Sync + 'static,

Chain this handler with the async filter projection proj.

Source

pub fn map<Proj, NewType, Args>(self, proj: Proj) -> Handler<'a, Output, Descr>
where Asyncify<Proj>: Injectable<NewType, Args> + Send + Sync + 'a, NewType: Send + Sync + 'static,

Chain this handler with the map projection proj.

Source

pub fn map_async<Proj, NewType, Args>( self, proj: Proj, ) -> Handler<'a, Output, Descr>
where Proj: Injectable<NewType, Args> + Send + Sync + 'a, NewType: Send + Sync + 'static,

Chain this handler with the async map projection proj.

Examples found in repository?
examples/middlewares.rs (line 16)
6async fn main() {
7    pretty_env_logger::init();
8    log::info!("Starting middlewares bot...");
9
10    let bot = Bot::from_env();
11
12    let handler = Update::filter_message()
13        // Executes before the endpoint.
14        .inspect(|msg: Message| println!("Before (message #{}).", msg.id))
15        // Our "endpoint".
16        .map_async(my_endpoint)
17        // Executes after the endpoint (even if it fails).
18        .inspect(|msg: Message| {
19            println!("After (message #{}).", msg.id);
20        })
21        // Retrieve the result of the endpoint and pass it to the dispatcher.
22        .endpoint(|result: HandlerResult| async move {
23            // Alternatively, we could also pattern-match on this value for more
24            // fine-grained behaviour.
25            result
26        });
27
28    Dispatcher::builder(bot, handler).enable_ctrlc_handler().build().dispatch().await;
29}
More examples
Hide additional examples
examples/middlewares_fallible.rs (line 16)
6async fn main() {
7    pretty_env_logger::init();
8    log::info!("Starting middlewares_fallible bot...");
9
10    let bot = Bot::from_env();
11
12    let handler = Update::filter_message()
13        // Executes before the endpoint.
14        .inspect(|msg: Message| println!("Before (message #{}).", msg.id))
15        // Our "endpoint".
16        .map_async(my_endpoint)
17        // Executes after the endpoint. If the endpoint failed, print an error message and stop
18        // execution; if not, continue.
19        .filter(|result: HandlerResult, msg: Message| {
20            println!("In-between (message #{}).", msg.id);
21            match result {
22                Ok(()) => true,
23                Err(err) => {
24                    eprintln!("Our endpoint failed: {err}");
25                    false
26                }
27            }
28        })
29        // Executes only if the endpoint succeeded.
30        .endpoint(|msg: Message| async move {
31            println!("After (message #{}).", msg.id);
32            HandlerResult::Ok(())
33        });
34
35    Dispatcher::builder(bot, handler).enable_ctrlc_handler().build().dispatch().await;
36}
Source

pub fn inspect<F, Args>(self, f: F) -> Handler<'a, Output, Descr>
where Asyncify<F>: Injectable<(), Args> + Send + Sync + 'a,

Chain this handler with the inspection function f.

Examples found in repository?
examples/middlewares.rs (line 14)
6async fn main() {
7    pretty_env_logger::init();
8    log::info!("Starting middlewares bot...");
9
10    let bot = Bot::from_env();
11
12    let handler = Update::filter_message()
13        // Executes before the endpoint.
14        .inspect(|msg: Message| println!("Before (message #{}).", msg.id))
15        // Our "endpoint".
16        .map_async(my_endpoint)
17        // Executes after the endpoint (even if it fails).
18        .inspect(|msg: Message| {
19            println!("After (message #{}).", msg.id);
20        })
21        // Retrieve the result of the endpoint and pass it to the dispatcher.
22        .endpoint(|result: HandlerResult| async move {
23            // Alternatively, we could also pattern-match on this value for more
24            // fine-grained behaviour.
25            result
26        });
27
28    Dispatcher::builder(bot, handler).enable_ctrlc_handler().build().dispatch().await;
29}
More examples
Hide additional examples
examples/middlewares_fallible.rs (line 14)
6async fn main() {
7    pretty_env_logger::init();
8    log::info!("Starting middlewares_fallible bot...");
9
10    let bot = Bot::from_env();
11
12    let handler = Update::filter_message()
13        // Executes before the endpoint.
14        .inspect(|msg: Message| println!("Before (message #{}).", msg.id))
15        // Our "endpoint".
16        .map_async(my_endpoint)
17        // Executes after the endpoint. If the endpoint failed, print an error message and stop
18        // execution; if not, continue.
19        .filter(|result: HandlerResult, msg: Message| {
20            println!("In-between (message #{}).", msg.id);
21            match result {
22                Ok(()) => true,
23                Err(err) => {
24                    eprintln!("Our endpoint failed: {err}");
25                    false
26                }
27            }
28        })
29        // Executes only if the endpoint succeeded.
30        .endpoint(|msg: Message| async move {
31            println!("After (message #{}).", msg.id);
32            HandlerResult::Ok(())
33        });
34
35    Dispatcher::builder(bot, handler).enable_ctrlc_handler().build().dispatch().await;
36}
examples/chat_member_updates.rs (lines 25-27)
16async fn main() -> ResponseResult<()> {
17    pretty_env_logger::init();
18
19    // We specify default parse mode to be `Html`, so that later we can use
20    // `html::user_mention`
21    let bot = ronami::Bot::from_env().parse_mode(ParseMode::Html);
22
23    // Create a handler for our bot, that will process updates from Telegram
24    let handler = dptree::entry()
25        .inspect(|u: Update| {
26            eprintln!("{u:#?}"); // Print the update to the console with inspect
27        })
28        .branch(
29            Update::filter_chat_member()
30                .branch(
31                    dptree::filter(|m: ChatMemberUpdated| {
32                        m.old_chat_member.is_left() && m.new_chat_member.is_present()
33                    })
34                    .endpoint(new_chat_member),
35                )
36                .branch(
37                    dptree::filter(|m: ChatMemberUpdated| {
38                        m.old_chat_member.is_present() && m.new_chat_member.is_left()
39                    })
40                    .endpoint(left_chat_member),
41                ),
42        );
43
44    // Create a dispatcher for our bot
45    Dispatcher::builder(bot, handler).enable_ctrlc_handler().build().dispatch().await;
46
47    Ok(())
48}
Source

pub fn inspect_async<F, Args>(self, f: F) -> Handler<'a, Output, Descr>
where F: Injectable<(), Args> + Send + Sync + 'a,

Chain this handler with the async inspection function f.

Source

pub fn endpoint<F, FnArgs>(self, f: F) -> Handler<'a, Output, Descr>
where F: Injectable<Output, FnArgs> + Send + Sync + 'a, Output: 'static,

Chain this handler with the endpoint handler f.

Examples found in repository?
examples/buttons.rs (line 31)
24async fn main() -> Result<(), Box<dyn Error>> {
25    pretty_env_logger::init();
26    log::info!("Starting buttons bot...");
27
28    let bot = Bot::from_env();
29
30    let handler = dptree::entry()
31        .branch(Update::filter_message().endpoint(message_handler))
32        .branch(Update::filter_callback_query().endpoint(callback_handler))
33        .branch(Update::filter_inline_query().endpoint(inline_query_handler));
34
35    Dispatcher::builder(bot, handler).enable_ctrlc_handler().build().dispatch().await;
36    Ok(())
37}
More examples
Hide additional examples
examples/deep_linking.rs (line 50)
40async fn main() {
41    pretty_env_logger::init();
42    log::info!("Starting deep linking bot...");
43
44    let bot = Bot::from_env();
45
46    let handler = dialogue::enter::<Update, InMemStorage<State>, State, _>()
47        .branch(
48            Update::filter_message()
49                .filter_command::<StartCommand>()
50                .branch(case![StartCommand::Start(start)].endpoint(start)),
51        )
52        .branch(
53            Update::filter_message()
54                .branch(case![State::WriteToSomeone { id }].endpoint(send_message)),
55        );
56
57    Dispatcher::builder(bot, handler)
58        .dependencies(deps![InMemStorage::<State>::new()])
59        .enable_ctrlc_handler()
60        .build()
61        .dispatch()
62        .await;
63}
examples/dialogue.rs (line 46)
36async fn main() {
37    pretty_env_logger::init();
38    log::info!("Starting dialogue bot...");
39
40    let bot = Bot::from_env();
41
42    Dispatcher::builder(
43        bot,
44        Update::filter_message()
45            .enter_dialogue::<Message, InMemStorage<State>, State>()
46            .branch(dptree::case![State::Start].endpoint(start))
47            .branch(dptree::case![State::ReceiveFullName].endpoint(receive_full_name))
48            .branch(dptree::case![State::ReceiveAge { full_name }].endpoint(receive_age))
49            .branch(
50                dptree::case![State::ReceiveLocation { full_name, age }].endpoint(receive_location),
51            ),
52    )
53    .dependencies(dptree::deps![InMemStorage::<State>::new()])
54    .enable_ctrlc_handler()
55    .build()
56    .dispatch()
57    .await;
58}
examples/shared_state.rs (lines 18-25)
11async fn main() {
12    pretty_env_logger::init();
13    log::info!("Starting shared state bot...");
14
15    let bot = Bot::from_env();
16    let messages_total = Arc::new(AtomicU64::new(0));
17
18    let handler = Update::filter_message().endpoint(
19        |bot: Bot, messages_total: Arc<AtomicU64>, msg: Message| async move {
20            let previous = messages_total.fetch_add(1, Ordering::Relaxed);
21            bot.send_message(msg.chat.id, format!("I received {previous} messages in total."))
22                .await?;
23            respond(())
24        },
25    );
26
27    Dispatcher::builder(bot, handler)
28        // Pass the shared state to the handler as a dependency.
29        .dependencies(dptree::deps![messages_total])
30        .enable_ctrlc_handler()
31        .build()
32        .dispatch()
33        .await;
34}
examples/middlewares.rs (lines 22-26)
6async fn main() {
7    pretty_env_logger::init();
8    log::info!("Starting middlewares bot...");
9
10    let bot = Bot::from_env();
11
12    let handler = Update::filter_message()
13        // Executes before the endpoint.
14        .inspect(|msg: Message| println!("Before (message #{}).", msg.id))
15        // Our "endpoint".
16        .map_async(my_endpoint)
17        // Executes after the endpoint (even if it fails).
18        .inspect(|msg: Message| {
19            println!("After (message #{}).", msg.id);
20        })
21        // Retrieve the result of the endpoint and pass it to the dispatcher.
22        .endpoint(|result: HandlerResult| async move {
23            // Alternatively, we could also pattern-match on this value for more
24            // fine-grained behaviour.
25            result
26        });
27
28    Dispatcher::builder(bot, handler).enable_ctrlc_handler().build().dispatch().await;
29}
examples/purchase.rs (line 68)
62fn schema() -> UpdateHandler<Box<dyn std::error::Error + Send + Sync + 'static>> {
63    use dptree::case;
64
65    let command_handler = ronami::filter_command::<Command, _>()
66        .branch(
67            case![State::Start]
68                .branch(case![Command::Help].endpoint(help))
69                .branch(case![Command::Start].endpoint(start)),
70        )
71        .branch(case![Command::Cancel].endpoint(cancel));
72
73    let message_handler = Update::filter_message()
74        .branch(command_handler)
75        .branch(case![State::ReceiveFullName].endpoint(receive_full_name))
76        .branch(dptree::endpoint(invalid_state));
77
78    let callback_query_handler = Update::filter_callback_query().branch(
79        case![State::ReceiveProductChoice { full_name }].endpoint(receive_product_selection),
80    );
81
82    dialogue::enter::<Update, InMemStorage<State>, State, _>()
83        .branch(message_handler)
84        .branch(callback_query_handler)
85}

Trait Implementations§

Source§

impl<Output, Descr> Clone for Handler<'_, Output, Descr>

Source§

fn clone(&self) -> Handler<'_, Output, Descr>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Output> HandlerExt<Output> for Handler<'static, Output, DpHandlerDescription>
where Output: Send + Sync + 'static,

Source§

fn filter_command<C>(self) -> Self
where C: BotCommands + Send + Sync + 'static,

Returns a handler that accepts a parsed command C. Read more
Source§

fn filter_mention_command<C>(self) -> Self
where C: BotCommands + Send + Sync + 'static,

Returns a handler that accepts a parsed command C if the command contains a bot mention, for example /start@my_bot. Read more
Source§

fn enter_dialogue<Upd, S, D>(self) -> Self
where S: Storage<D> + ?Sized + Send + Sync + 'static, <S as Storage<D>>::Error: Debug + Send, D: Default + Clone + Send + Sync + 'static, Upd: GetChatId + Clone + Send + Sync + 'static,

Passes Dialogue<D, S> and D as handler dependencies. Read more

Auto Trait Implementations§

§

impl<'a, Output, Descr = Unspecified> !RefUnwindSafe for Handler<'a, Output, Descr>

§

impl<'a, Output, Descr = Unspecified> !UnwindSafe for Handler<'a, Output, Descr>

§

impl<'a, Output, Descr> Freeze for Handler<'a, Output, Descr>
where Arc<HandlerData<Descr, dyn Fn(DependencyMap, Box<dyn FnOnce(DependencyMap) -> Pin<Box<dyn Future<Output = ControlFlow<Output, DependencyMap>> + Send + 'a>> + Send + Sync + 'a>) -> Pin<Box<dyn Future<Output = ControlFlow<Output, DependencyMap>> + Send + 'a>> + Send + Sync + 'a>>: Freeze,

§

impl<'a, Output, Descr> Send for Handler<'a, Output, Descr>
where Arc<HandlerData<Descr, dyn Fn(DependencyMap, Box<dyn FnOnce(DependencyMap) -> Pin<Box<dyn Future<Output = ControlFlow<Output, DependencyMap>> + Send + 'a>> + Send + Sync + 'a>) -> Pin<Box<dyn Future<Output = ControlFlow<Output, DependencyMap>> + Send + 'a>> + Send + Sync + 'a>>: Send,

§

impl<'a, Output, Descr> Sync for Handler<'a, Output, Descr>
where Arc<HandlerData<Descr, dyn Fn(DependencyMap, Box<dyn FnOnce(DependencyMap) -> Pin<Box<dyn Future<Output = ControlFlow<Output, DependencyMap>> + Send + 'a>> + Send + Sync + 'a>) -> Pin<Box<dyn Future<Output = ControlFlow<Output, DependencyMap>> + Send + 'a>> + Send + Sync + 'a>>: Sync,

§

impl<'a, Output, Descr> Unpin for Handler<'a, Output, Descr>
where Arc<HandlerData<Descr, dyn Fn(DependencyMap, Box<dyn FnOnce(DependencyMap) -> Pin<Box<dyn Future<Output = ControlFlow<Output, DependencyMap>> + Send + 'a>> + Send + Sync + 'a>) -> Pin<Box<dyn Future<Output = ControlFlow<Output, DependencyMap>> + Send + 'a>> + Send + Sync + 'a>>: Unpin,

§

impl<'a, Output, Descr> UnsafeUnpin for Handler<'a, Output, Descr>
where Arc<HandlerData<Descr, dyn Fn(DependencyMap, Box<dyn FnOnce(DependencyMap) -> Pin<Box<dyn Future<Output = ControlFlow<Output, DependencyMap>> + Send + 'a>> + Send + Sync + 'a>) -> Pin<Box<dyn Future<Output = ControlFlow<Output, DependencyMap>> + Send + 'a>> + Send + Sync + 'a>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Erasable for T

Source§

const ACK_1_1_0: bool = true

Available on non-enforce_1_1_0_semantics only.
Whether this implementor has acknowledged the 1.1.0 update to unerase’s documented implementation requirements. Read more
Source§

unsafe fn unerase(this: NonNull<Erased>) -> NonNull<T>

Unerase this erased pointer. Read more
Source§

fn erase(this: NonNull<Self>) -> NonNull<Erased>

Turn this erasable pointer into an erased pointer. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more