pub struct StringRegexHandler { /* private fields */ }Expand description
Handler that matches messages whose text matches a regex pattern.
Uses regex::Regex::captures (anchored at the start of the string,
matching re.match from Python).
When the regex contains named capture groups, both context.matches
(positional) and context.named_matches (named groups map) are
populated.
§Example
ⓘ
use rust_tg_bot_ext::handlers::string_regex::StringRegexHandler;
use rust_tg_bot_ext::handlers::base::*;
use regex::Regex;
use std::sync::Arc;
let handler = StringRegexHandler::new(
Regex::new(r"^hello (\w+)").unwrap(),
Arc::new(|update, mr| Box::pin(async move { HandlerResult::Continue })),
true,
);Implementations§
Source§impl StringRegexHandler
impl StringRegexHandler
Sourcepub fn new(pattern: Regex, callback: HandlerCallback, block: bool) -> Self
pub fn new(pattern: Regex, callback: HandlerCallback, block: bool) -> Self
Create a new StringRegexHandler.
Trait Implementations§
Source§impl Handler for StringRegexHandler
impl Handler for StringRegexHandler
Source§fn collect_additional_context(
&self,
context: &mut CallbackContext,
match_result: &MatchResult,
)
fn collect_additional_context( &self, context: &mut CallbackContext, match_result: &MatchResult, )
Populate context.matches (positional) and context.named_matches
(named groups) from the regex match result.
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 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 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 moreAuto Trait Implementations§
impl Freeze for StringRegexHandler
impl !RefUnwindSafe for StringRegexHandler
impl Send for StringRegexHandler
impl Sync for StringRegexHandler
impl Unpin for StringRegexHandler
impl UnsafeUnpin for StringRegexHandler
impl !UnwindSafe for StringRegexHandler
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