pub struct FnHandler { /* private fields */ }Expand description
A lightweight handler that pairs a predicate with an async callback.
FnHandler bridges the gap between raw application::Handler structs and
the typed handler trait system. It implements Handler so it can be
registered via [Application::add_handler].
§Examples
ⓘ
use rust_tg_bot::ext::prelude::*;
use rust_tg_bot::ext::handlers::base::FnHandler;
async fn button_handler(update: Update, context: Context) -> HandlerResult {
// handle callback query ...
Ok(())
}
// Register with a predicate:
app.add_handler(
FnHandler::new(|u| u.callback_query().is_some(), button_handler),
0,
).await;
// Or use a convenience constructor:
app.add_handler(FnHandler::on_callback_query(button_handler), 0).await;Implementations§
Source§impl FnHandler
impl FnHandler
Sourcepub fn new<C, Cb, Fut>(check: C, callback: Cb) -> FnHandler
pub fn new<C, Cb, Fut>(check: C, callback: Cb) -> FnHandler
Create a new FnHandler with a custom predicate and an async callback.
The callback receives (Update, CallbackContext) and returns
Result<(), HandlerError>.
Sourcepub fn on_callback_query<Cb, Fut>(callback: Cb) -> FnHandler
pub fn on_callback_query<Cb, Fut>(callback: Cb) -> FnHandler
Match updates that have a callback_query.
Sourcepub fn on_inline_query<Cb, Fut>(callback: Cb) -> FnHandler
pub fn on_inline_query<Cb, Fut>(callback: Cb) -> FnHandler
Match updates that have an inline_query.
Sourcepub fn on_poll_answer<Cb, Fut>(callback: Cb) -> FnHandler
pub fn on_poll_answer<Cb, Fut>(callback: Cb) -> FnHandler
Match updates that have a poll_answer.
Sourcepub fn on_shipping_query<Cb, Fut>(callback: Cb) -> FnHandler
pub fn on_shipping_query<Cb, Fut>(callback: Cb) -> FnHandler
Match updates that have a shipping_query.
Sourcepub fn on_pre_checkout_query<Cb, Fut>(callback: Cb) -> FnHandler
pub fn on_pre_checkout_query<Cb, Fut>(callback: Cb) -> FnHandler
Match updates that have a pre_checkout_query.
Sourcepub fn on_chat_member<Cb, Fut>(callback: Cb) -> FnHandler
pub fn on_chat_member<Cb, Fut>(callback: Cb) -> FnHandler
Match updates that have a chat_member.
Sourcepub fn on_my_chat_member<Cb, Fut>(callback: Cb) -> FnHandler
pub fn on_my_chat_member<Cb, Fut>(callback: Cb) -> FnHandler
Match updates that have a my_chat_member.
Sourcepub fn on_message<Cb, Fut>(callback: Cb) -> FnHandler
pub fn on_message<Cb, Fut>(callback: Cb) -> FnHandler
Match updates that have a message.
Trait Implementations§
Source§impl Handler for FnHandler
impl Handler for FnHandler
Source§fn check_update(&self, update: &Update) -> Option<MatchResult>
fn check_update(&self, update: &Update) -> Option<MatchResult>
Determine whether this handler is interested in
update. Read moreSource§fn handle_update(
&self,
_update: Arc<Update>,
_match_result: MatchResult,
) -> Pin<Box<dyn Future<Output = HandlerResult> + Send>>
fn handle_update( &self, _update: Arc<Update>, _match_result: MatchResult, ) -> Pin<Box<dyn Future<Output = HandlerResult> + Send>>
Process the update. Called only when
check_update
returned Some.Source§fn handle_update_with_context(
&self,
update: Arc<Update>,
_match_result: MatchResult,
context: CallbackContext,
) -> Pin<Box<dyn Future<Output = HandlerResult> + Send>>
fn handle_update_with_context( &self, update: Arc<Update>, _match_result: MatchResult, context: CallbackContext, ) -> Pin<Box<dyn Future<Output = HandlerResult> + Send>>
Process the update with an Application-provided
CallbackContext. Read moreSource§fn block(&self) -> bool
fn block(&self) -> bool
Whether the application should block on this handler’s future before
dispatching to the next handler group.
Source§fn collect_additional_context(
&self,
_context: &mut CallbackContext,
_match_result: &MatchResult,
)
fn collect_additional_context( &self, _context: &mut CallbackContext, _match_result: &MatchResult, )
Populate additional context fields (e.g.
context.args, context.matches)
from the match result before the handler callback is invoked. Read moreAuto Trait Implementations§
impl Freeze for FnHandler
impl !RefUnwindSafe for FnHandler
impl Send for FnHandler
impl Sync for FnHandler
impl Unpin for FnHandler
impl UnsafeUnpin for FnHandler
impl !UnwindSafe for FnHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more