Merge pull request #127 from teloxide/polish-filter-dp-docs

Polish the docs of FilterDispatcher
This commit is contained in:
Temirkhan Myrzamadi 2020-01-06 22:31:21 +06:00 committed by GitHub
commit 4084bd31bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,
} }