Skip to content

Commit

Permalink
Rename Chainable to Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-zahner committed Apr 22, 2024
1 parent e3a236b commit ddcca65
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
22 changes: 11 additions & 11 deletions lychee-lib/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
//! lychee is based on a chain of responsibility, where each handler can modify
//! a request and decide if it should be passed to the next element or not.
//!
//! The chain is implemented as a vector of [`Chainable`] handlers. It is
//! The chain is implemented as a vector of [`Handler`] handlers. It is
//! traversed by calling [`Chain::traverse`], which will call
//! [`Chainable::chain`] on each handler in the chain consecutively.
//! [`Handler::chain`] on each handler in the chain consecutively.
//!
//! To add external handlers, you can implement the [`Chainable`] trait and add
//! To add external handlers, you can implement the [`Handler`] trait and add
//! the handler to the chain.
//!
//! [pattern]: https://github.com/lpxxn/rust-design-pattern/blob/master/behavioral/chain_of_responsibility.rs
Expand Down Expand Up @@ -44,10 +44,10 @@ pub(crate) type RequestChain = Chain<reqwest::Request, Status>;
/// This holds all handlers, which were chained together.
/// Handlers are traversed in order.
///
/// Each handler needs to implement the `Chainable` trait and be `Send`, because
/// Each handler needs to implement the `Handler` trait and be `Send`, because
/// the chain is traversed concurrently and the handlers can be sent between
/// threads.
pub(crate) type InnerChain<T, R> = Vec<Box<dyn Chainable<T, R> + Send>>;
pub(crate) type InnerChain<T, R> = Vec<Box<dyn Handler<T, R> + Send>>;

/// The outer chain type.
///
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<T, R> Chain<T, R> {
}
}

/// Chainable trait for implementing request handlers
/// Handler trait for implementing request handlers
///
/// This trait needs to be implemented by all chainable handlers.
/// It is the only requirement to handle requests in lychee.
Expand All @@ -112,7 +112,7 @@ impl<T, R> Chain<T, R> {
/// handler. This allows for modifying the request, such as adding headers or
/// changing the URL (e.g. for remapping or filtering).
#[async_trait]
pub trait Chainable<T, R>: Debug {
pub trait Handler<T, R>: Debug {
/// Given an input request, return a [`ChainResult`] to continue or stop the
/// chain.
///
Expand All @@ -122,15 +122,15 @@ pub trait Chainable<T, R>: Debug {
/// # Example
///
/// ```
/// use lychee_lib::{Chainable, ChainResult, Status};
/// use lychee_lib::{Handler, ChainResult, Status};
/// use reqwest::Request;
/// use async_trait::async_trait;
///
/// #[derive(Debug)]
/// struct AddHeader;
///
/// #[async_trait]
/// impl Chainable<Request, Status> for AddHeader {
/// impl Handler<Request, Status> for AddHeader {
/// async fn chain(&mut self, mut request: Request) -> ChainResult<Request, Status> {
/// // You can modify the request however you like here
/// request.headers_mut().append("X-Header", "value".parse().unwrap());
Expand Down Expand Up @@ -183,7 +183,7 @@ mod test {
use super::{
ChainResult,
ChainResult::{Done, Next},
Chainable,
Handler,
};
use async_trait::async_trait;

Expand All @@ -194,7 +194,7 @@ mod test {
struct Result(usize);

#[async_trait]
impl Chainable<Result, Result> for Add {
impl Handler<Result, Result> for Add {
async fn chain(&mut self, req: Result) -> ChainResult<Result, Result> {
let added = req.0 + self.0;
if added > 100 {
Expand Down
4 changes: 2 additions & 2 deletions lychee-lib/src/checker.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
chain::{ChainResult, Chainable},
chain::{ChainResult, Handler},
retry::RetryExt,
Status,
};
Expand Down Expand Up @@ -73,7 +73,7 @@ fn clone_unwrap(request: &Request) -> Request {
}

#[async_trait]
impl Chainable<Request, Status> for Checker {
impl Handler<Request, Status> for Checker {
async fn chain(&mut self, input: Request) -> ChainResult<Request, Status> {
ChainResult::Done(self.retry_request(input).await)
}
Expand Down
4 changes: 2 additions & 2 deletions lychee-lib/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ mod tests {

use super::ClientBuilder;
use crate::{
chain::{ChainResult, Chainable, RequestChain},
chain::{ChainResult, Handler, RequestChain},
mock_server,
test_utils::get_mock_client_response,
Request, Status, Uri,
Expand Down Expand Up @@ -1086,7 +1086,7 @@ mod tests {
struct ExampleHandler();

#[async_trait]
impl Chainable<Request, Status> for ExampleHandler {
impl Handler<Request, Status> for ExampleHandler {
async fn chain(&mut self, _: Request) -> ChainResult<Request, Status> {
ChainResult::Done(Status::Excluded)
}
Expand Down
4 changes: 2 additions & 2 deletions lychee-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ use openssl_sys as _; // required for vendored-openssl feature
#[doc(inline)]
pub use crate::{
basic_auth::BasicAuthExtractor,
// Expose the `Chainable` trait to allow defining external handlers (plugins)
chain::{ChainResult, Chainable},
// Expose the `Handler` trait to allow defining external handlers (plugins)
chain::{ChainResult, Handler},
// Constants get exposed so that the CLI can use the same defaults as the library
client::{
check, Client, ClientBuilder, DEFAULT_MAX_REDIRECTS, DEFAULT_MAX_RETRIES,
Expand Down
4 changes: 2 additions & 2 deletions lychee-lib/src/quirks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
chain::{ChainResult, Chainable},
chain::{ChainResult, Handler},
Status,
};
use async_trait::async_trait;
Expand Down Expand Up @@ -92,7 +92,7 @@ impl Quirks {
}

#[async_trait]
impl Chainable<Request, Status> for Quirks {
impl Handler<Request, Status> for Quirks {
async fn chain(&mut self, input: Request) -> ChainResult<Request, Status> {
ChainResult::Next(self.apply(input))
}
Expand Down
4 changes: 2 additions & 2 deletions lychee-lib/src/types/basic_auth/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use reqwest::Request;
use serde::Deserialize;
use thiserror::Error;

use crate::chain::{ChainResult, Chainable};
use crate::chain::{ChainResult, Handler};
use crate::Status;

#[derive(Copy, Clone, Debug, Error, PartialEq)]
Expand Down Expand Up @@ -75,7 +75,7 @@ impl BasicAuthCredentials {
}

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

0 comments on commit ddcca65

Please sign in to comment.