Skip to content

Commit 50bd88a

Browse files
committed
Rename Chainable to Handler
1 parent c228a8b commit 50bd88a

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

lychee-lib/src/chain/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
//! lychee is based on a chain of responsibility, where each handler can modify
44
//! a request and decide if it should be passed to the next element or not.
55
//!
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
77
//! 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.
99
//!
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
1111
//! the handler to the chain.
1212
//!
1313
//! [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>;
4444
/// This holds all handlers, which were chained together.
4545
/// Handlers are traversed in order.
4646
///
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
4848
/// the chain is traversed concurrently and the handlers can be sent between
4949
/// 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>>;
5151

5252
/// The outer chain type.
5353
///
@@ -99,7 +99,7 @@ impl<T, R> Chain<T, R> {
9999
}
100100
}
101101

102-
/// Chainable trait for implementing request handlers
102+
/// Handler trait for implementing request handlers
103103
///
104104
/// This trait needs to be implemented by all chainable handlers.
105105
/// It is the only requirement to handle requests in lychee.
@@ -112,7 +112,7 @@ impl<T, R> Chain<T, R> {
112112
/// handler. This allows for modifying the request, such as adding headers or
113113
/// changing the URL (e.g. for remapping or filtering).
114114
#[async_trait]
115-
pub trait Chainable<T, R>: Debug {
115+
pub trait Handler<T, R>: Debug {
116116
/// Given an input request, return a [`ChainResult`] to continue or stop the
117117
/// chain.
118118
///
@@ -122,15 +122,15 @@ pub trait Chainable<T, R>: Debug {
122122
/// # Example
123123
///
124124
/// ```
125-
/// use lychee_lib::{Chainable, ChainResult, Status};
125+
/// use lychee_lib::{Handler, ChainResult, Status};
126126
/// use reqwest::Request;
127127
/// use async_trait::async_trait;
128128
///
129129
/// #[derive(Debug)]
130130
/// struct AddHeader;
131131
///
132132
/// #[async_trait]
133-
/// impl Chainable<Request, Status> for AddHeader {
133+
/// impl Handler<Request, Status> for AddHeader {
134134
/// async fn chain(&mut self, mut request: Request) -> ChainResult<Request, Status> {
135135
/// // You can modify the request however you like here
136136
/// request.headers_mut().append("X-Header", "value".parse().unwrap());
@@ -183,7 +183,7 @@ mod test {
183183
use super::{
184184
ChainResult,
185185
ChainResult::{Done, Next},
186-
Chainable,
186+
Handler,
187187
};
188188
use async_trait::async_trait;
189189

@@ -194,7 +194,7 @@ mod test {
194194
struct Result(usize);
195195

196196
#[async_trait]
197-
impl Chainable<Result, Result> for Add {
197+
impl Handler<Result, Result> for Add {
198198
async fn chain(&mut self, req: Result) -> ChainResult<Result, Result> {
199199
let added = req.0 + self.0;
200200
if added > 100 {

lychee-lib/src/checker.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
chain::{ChainResult, Chainable},
2+
chain::{ChainResult, Handler},
33
retry::RetryExt,
44
Status,
55
};
@@ -73,7 +73,7 @@ fn clone_unwrap(request: &Request) -> Request {
7373
}
7474

7575
#[async_trait]
76-
impl Chainable<Request, Status> for Checker {
76+
impl Handler<Request, Status> for Checker {
7777
async fn chain(&mut self, input: Request) -> ChainResult<Request, Status> {
7878
ChainResult::Done(self.retry_request(input).await)
7979
}

lychee-lib/src/client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ mod tests {
750750

751751
use super::ClientBuilder;
752752
use crate::{
753-
chain::{ChainResult, Chainable, RequestChain},
753+
chain::{ChainResult, Handler, RequestChain},
754754
mock_server,
755755
test_utils::get_mock_client_response,
756756
Request, Status, Uri,
@@ -1086,7 +1086,7 @@ mod tests {
10861086
struct ExampleHandler();
10871087

10881088
#[async_trait]
1089-
impl Chainable<Request, Status> for ExampleHandler {
1089+
impl Handler<Request, Status> for ExampleHandler {
10901090
async fn chain(&mut self, _: Request) -> ChainResult<Request, Status> {
10911091
ChainResult::Done(Status::Excluded)
10921092
}

lychee-lib/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ use openssl_sys as _; // required for vendored-openssl feature
8585
#[doc(inline)]
8686
pub use crate::{
8787
basic_auth::BasicAuthExtractor,
88-
// Expose the `Chainable` trait to allow defining external handlers (plugins)
89-
chain::{ChainResult, Chainable},
88+
// Expose the `Handler` trait to allow defining external handlers (plugins)
89+
chain::{ChainResult, Handler},
9090
// Constants get exposed so that the CLI can use the same defaults as the library
9191
client::{
9292
check, Client, ClientBuilder, DEFAULT_MAX_REDIRECTS, DEFAULT_MAX_RETRIES,

lychee-lib/src/quirks/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
chain::{ChainResult, Chainable},
2+
chain::{ChainResult, Handler},
33
Status,
44
};
55
use async_trait::async_trait;
@@ -92,7 +92,7 @@ impl Quirks {
9292
}
9393

9494
#[async_trait]
95-
impl Chainable<Request, Status> for Quirks {
95+
impl Handler<Request, Status> for Quirks {
9696
async fn chain(&mut self, input: Request) -> ChainResult<Request, Status> {
9797
ChainResult::Next(self.apply(input))
9898
}

lychee-lib/src/types/basic_auth/credentials.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use reqwest::Request;
88
use serde::Deserialize;
99
use thiserror::Error;
1010

11-
use crate::chain::{ChainResult, Chainable};
11+
use crate::chain::{ChainResult, Handler};
1212
use crate::Status;
1313

1414
#[derive(Copy, Clone, Debug, Error, PartialEq)]
@@ -75,7 +75,7 @@ impl BasicAuthCredentials {
7575
}
7676

7777
#[async_trait]
78-
impl Chainable<Request, Status> for Option<BasicAuthCredentials> {
78+
impl Handler<Request, Status> for Option<BasicAuthCredentials> {
7979
async fn chain(&mut self, mut request: Request) -> ChainResult<Request, Status> {
8080
if let Some(credentials) = self {
8181
request

0 commit comments

Comments
 (0)