mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-10 12:02:22 +01:00
Merge pull request #127 from teloxide/polish-filter-dp-docs
Polish the docs of FilterDispatcher
This commit is contained in:
commit
4084bd31bf
1 changed files with 44 additions and 13 deletions
|
@ -22,13 +22,41 @@ type FiltersWithHandlers<'a, T, E> = Vec<FilterWithHandler<'a, T, E>>;
|
||||||
/// [`Handler`].
|
/// [`Handler`].
|
||||||
/// 2. Filters and handlers.
|
/// 2. Filters and handlers.
|
||||||
///
|
///
|
||||||
/// First you register filters and handlers using the methods defined below, and
|
/// First you call [`FilterDispatcher::new(eh)`] to create this dispatcher. `eh`
|
||||||
/// then you call [`.dispatch(updater)`]. Filters and handlers are executed in
|
/// stands for **E**rror **H**andler, you can simply provide a closure that
|
||||||
/// order of registering. The following flowchart represents how this dispatcher
|
/// takes [`Either<UpdaterE, HandlerE>`]:
|
||||||
/// acts:
|
///
|
||||||
|
/// ```
|
||||||
|
/// use either::Either;
|
||||||
|
/// use std::convert::Infallible;
|
||||||
|
/// use teloxide::{dispatching::FilterDispatcher, RequestError};
|
||||||
|
///
|
||||||
|
/// let _ =
|
||||||
|
/// FilterDispatcher::new(|err: Either<RequestError, Infallible>| async {
|
||||||
|
/// dbg!(err);
|
||||||
|
/// });
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// Or you can do it even simpler by providing the built-in error handler
|
||||||
|
/// [`Print`]:
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use std::convert::Infallible;
|
||||||
|
/// use teloxide::{
|
||||||
|
/// dispatching::{error_handlers::Print, FilterDispatcher},
|
||||||
|
/// RequestError,
|
||||||
|
/// };
|
||||||
|
///
|
||||||
|
/// let _ = FilterDispatcher::<'_, Infallible, _>::new::<RequestError>(Print);
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// And then you register filters and handlers using the methods defined below,
|
||||||
|
/// and then you call [`.dispatch(updater)`]. Filters and handlers are executed
|
||||||
|
/// in order of registering. The following flowchart represents how this
|
||||||
|
/// dispatcher acts:
|
||||||
///
|
///
|
||||||
/// <div align="center">
|
/// <div align="center">
|
||||||
/// <img src="https://raw.githubusercontent.com/teloxide/teloxide/dev/media/FILTER_DP_FLOWCHART.png" width="700" />
|
/// <img src="https://raw.githubusercontent.com/teloxide/teloxide/dev/media/FILTER_DP_FLOWCHART.png" />
|
||||||
/// </div>
|
/// </div>
|
||||||
///
|
///
|
||||||
/// ## Examples
|
/// ## Examples
|
||||||
|
@ -73,15 +101,18 @@ type FiltersWithHandlers<'a, T, E> = Vec<FilterWithHandler<'a, T, E>>;
|
||||||
/// [`ErrorHandler`]: crate::dispatching::error_handlers::ErrorHandler
|
/// [`ErrorHandler`]: crate::dispatching::error_handlers::ErrorHandler
|
||||||
/// [`Updater`]: crate::dispatching::updaters::Updater
|
/// [`Updater`]: crate::dispatching::updaters::Updater
|
||||||
/// [`Handler`]: crate::dispatching::Handler
|
/// [`Handler`]: crate::dispatching::Handler
|
||||||
pub struct FilterDispatcher<'a, E, Eh> {
|
/// [`FilterDispatcher::new(eh)`]: FilterDispatcher::new
|
||||||
message_handlers: FiltersWithHandlers<'a, Message, E>,
|
/// [`Either<UpdaterE, HandlerE>`]: either::Either
|
||||||
edited_message_handlers: FiltersWithHandlers<'a, Message, E>,
|
/// [`Print`]: crate::dispatching::error_handlers::Print
|
||||||
channel_post_handlers: FiltersWithHandlers<'a, Message, E>,
|
pub struct FilterDispatcher<'a, HandlerE, Eh> {
|
||||||
edited_channel_post_handlers: FiltersWithHandlers<'a, Message, E>,
|
message_handlers: FiltersWithHandlers<'a, Message, HandlerE>,
|
||||||
inline_query_handlers: FiltersWithHandlers<'a, InlineQuery, E>,
|
edited_message_handlers: FiltersWithHandlers<'a, Message, HandlerE>,
|
||||||
|
channel_post_handlers: FiltersWithHandlers<'a, Message, HandlerE>,
|
||||||
|
edited_channel_post_handlers: FiltersWithHandlers<'a, Message, HandlerE>,
|
||||||
|
inline_query_handlers: FiltersWithHandlers<'a, InlineQuery, HandlerE>,
|
||||||
chosen_inline_result_handlers:
|
chosen_inline_result_handlers:
|
||||||
FiltersWithHandlers<'a, ChosenInlineResult, E>,
|
FiltersWithHandlers<'a, ChosenInlineResult, HandlerE>,
|
||||||
callback_query_handlers: FiltersWithHandlers<'a, CallbackQuery, E>,
|
callback_query_handlers: FiltersWithHandlers<'a, CallbackQuery, HandlerE>,
|
||||||
error_handler: Eh,
|
error_handler: Eh,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue