3
3
//! lychee is based on a chain of responsibility, where each handler can modify
4
4
//! a request and decide if it should be passed to the next element or not.
5
5
//!
6
- //! The chain is implemented as a vector of [`Chainable `] handlers. It is
6
+ //! The chain is implemented as a vector of [`Handler `] handlers. It is
7
7
//! traversed by calling [`Chain::traverse`], which will call
8
- //! [`Chainable ::chain`] on each handler in the chain consecutively.
8
+ //! [`Handler ::chain`] on each handler in the chain consecutively.
9
9
//!
10
- //! To add external handlers, you can implement the [`Chainable `] trait and add
10
+ //! To add external handlers, you can implement the [`Handler `] trait and add
11
11
//! the handler to the chain.
12
12
//!
13
13
//! [pattern]: https://github.com/lpxxn/rust-design-pattern/blob/master/behavioral/chain_of_responsibility.rs
@@ -44,10 +44,10 @@ pub(crate) type RequestChain = Chain<reqwest::Request, Status>;
44
44
/// This holds all handlers, which were chained together.
45
45
/// Handlers are traversed in order.
46
46
///
47
- /// Each handler needs to implement the `Chainable ` trait and be `Send`, because
47
+ /// Each handler needs to implement the `Handler ` trait and be `Send`, because
48
48
/// the chain is traversed concurrently and the handlers can be sent between
49
49
/// threads.
50
- pub ( crate ) type InnerChain < T , R > = Vec < Box < dyn Chainable < T , R > + Send > > ;
50
+ pub ( crate ) type InnerChain < T , R > = Vec < Box < dyn Handler < T , R > + Send > > ;
51
51
52
52
/// The outer chain type.
53
53
///
@@ -99,7 +99,7 @@ impl<T, R> Chain<T, R> {
99
99
}
100
100
}
101
101
102
- /// Chainable trait for implementing request handlers
102
+ /// Handler trait for implementing request handlers
103
103
///
104
104
/// This trait needs to be implemented by all chainable handlers.
105
105
/// It is the only requirement to handle requests in lychee.
@@ -112,7 +112,7 @@ impl<T, R> Chain<T, R> {
112
112
/// handler. This allows for modifying the request, such as adding headers or
113
113
/// changing the URL (e.g. for remapping or filtering).
114
114
#[ async_trait]
115
- pub trait Chainable < T , R > : Debug {
115
+ pub trait Handler < T , R > : Debug {
116
116
/// Given an input request, return a [`ChainResult`] to continue or stop the
117
117
/// chain.
118
118
///
@@ -122,15 +122,15 @@ pub trait Chainable<T, R>: Debug {
122
122
/// # Example
123
123
///
124
124
/// ```
125
- /// use lychee_lib::{Chainable , ChainResult, Status};
125
+ /// use lychee_lib::{Handler , ChainResult, Status};
126
126
/// use reqwest::Request;
127
127
/// use async_trait::async_trait;
128
128
///
129
129
/// #[derive(Debug)]
130
130
/// struct AddHeader;
131
131
///
132
132
/// #[async_trait]
133
- /// impl Chainable <Request, Status> for AddHeader {
133
+ /// impl Handler <Request, Status> for AddHeader {
134
134
/// async fn chain(&mut self, mut request: Request) -> ChainResult<Request, Status> {
135
135
/// // You can modify the request however you like here
136
136
/// request.headers_mut().append("X-Header", "value".parse().unwrap());
@@ -183,7 +183,7 @@ mod test {
183
183
use super :: {
184
184
ChainResult ,
185
185
ChainResult :: { Done , Next } ,
186
- Chainable ,
186
+ Handler ,
187
187
} ;
188
188
use async_trait:: async_trait;
189
189
@@ -194,7 +194,7 @@ mod test {
194
194
struct Result ( usize ) ;
195
195
196
196
#[ async_trait]
197
- impl Chainable < Result , Result > for Add {
197
+ impl Handler < Result , Result > for Add {
198
198
async fn chain ( & mut self , req : Result ) -> ChainResult < Result , Result > {
199
199
let added = req. 0 + self . 0 ;
200
200
if added > 100 {
0 commit comments