Skip to content

Commit

Permalink
Add docs for middlewares module
Browse files Browse the repository at this point in the history
  • Loading branch information
Desiders committed Sep 16, 2023
1 parent fe1ff69 commit b41cf8e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/middlewares.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
//! This module contains inner and outer middlewares.
//!
//! Middlewares are designed to be `inner` and `outer`.
//! You can read more about each middleware type in their modules:
//! - [`inner module`]
//! - [`outer module`]
//!
//! [`inner module`]: inner
//! [`outer module`]: outer
#![allow(clippy::module_name_repetitions)]

pub mod inner;
Expand Down
17 changes: 17 additions & 0 deletions src/middlewares/inner.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
//! This module contains inner middlewares.
//!
//! Middlewares are called `inner` if they called before handler, but after outer middlewares and filers.
//! These middlewares have access to the middlewares/handler-chain
//! and can modify the [`request`] (with [`context`] in it)/[`response`].
//!
//! Prefer to use inner middlewares over outer middlewares in some cases:
//! - If you need to call middlewares after filters and before handlers
//! - If you need to manipulate with call of next middleware or handler
//! - If you need to manipulate with [`request`] or [`response`]
//!
//! You can check example of using inner middlewares in `examples/stats_incoming_updates_middleware`.
//!
//! [`request`]: crate::event::telegram::HandlerRequest
//! [`response`]: crate::event::telegram::HandlerResponse
//! [`context`]: crate::context::Context
pub mod base;
pub mod logging;
pub mod manager;
Expand Down
17 changes: 17 additions & 0 deletions src/middlewares/outer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
//! This module contains outer middlewares.
//!
//! Middlewares are called `outer` if they called before filters, inner middlewares and handlers.
//! These middlewares have access to the [`request`] (with [`context`] in it),
//! but don't have access to the middlewares/handler-chain and the [`response`] (for these purposes, use [`inner middlewares`]).
//!
//! Prefer to use outer middlewares over inner middlewares in some cases:
//! - If you need to call middlewares before filters, inner middlewares and handlers
//! - If you need to manipulate with [`request`] and [`context`] in it
//!
//! You can check example of using outer middlewares in `examples/stats_incoming_updates_middleware`.
//!
//! [`request`]: crate::event::telegram::HandlerRequest
//! [`response`]: crate::event::telegram::HandlerResponse
//! [`context`]: crate::context::Context
//! [`inner middlewares`]: crate::middlewares::inner
pub mod base;
pub mod fsm_context;
pub mod manager;
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/outer/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub type MiddlewareResponse<Client> = (Request<Client>, EventReturn);
///
/// Prefer to use outer middlewares over inner middlewares in some cases:
/// - If you need to call middlewares before filters, inner middlewares and handlers
/// - If you need to manipulate with [`Request`]
/// - If you need to manipulate with [`Request`] and [`crate::context::Context`] in it
/// Usually outer middlewares are used to manipulate with [`Request`].
///
/// Implement this trait for your own middlewares
Expand Down

0 comments on commit b41cf8e

Please sign in to comment.