diff --git a/lychee-lib/src/chain/mod.rs b/lychee-lib/src/chain/mod.rs index 4585a33..6bdee55 100644 --- a/lychee-lib/src/chain/mod.rs +++ b/lychee-lib/src/chain/mod.rs @@ -4,8 +4,8 @@ use crate::Status; #[derive(Debug, PartialEq)] pub(crate) enum ChainResult { - Chained(T), - EarlyExit(R), + Next(T), + Done(R), } pub(crate) type RequestChain = Chain; @@ -31,15 +31,15 @@ impl Chain { pub(crate) fn traverse(&mut self, mut input: T) -> ChainResult { use ChainResult::*; for e in self.0.iter_mut() { - match e.handle(input) { - Chained(r) => input = r, - EarlyExit(r) => { - return EarlyExit(r); + match e.chain(input) { + Next(r) => input = r, + Done(r) => { + return Done(r); } } } - Chained(input) + Next(input) } pub(crate) fn push(&mut self, value: Box + Send>) { @@ -48,25 +48,25 @@ impl Chain { } pub(crate) trait Chainable: Debug { - fn handle(&mut self, input: T) -> ChainResult; + fn chain(&mut self, input: T) -> ChainResult; } mod test { use super::{ChainResult, ChainResult::*, Chainable}; #[derive(Debug)] - struct Add(i64); + struct Add(usize); #[derive(Debug, PartialEq, Eq)] - struct Result(i64); + struct Result(usize); impl Chainable for Add { - fn handle(&mut self, req: Result) -> ChainResult { + fn chain(&mut self, req: Result) -> ChainResult { let added = req.0 + self.0; if added > 100 { - EarlyExit(Result(req.0)) + Done(Result(req.0)) } else { - Chained(Result(added)) + Next(Result(added)) } } } @@ -75,9 +75,9 @@ mod test { fn simple_chain() { use super::Chain; let mut chain: Chain = - Chain::new(vec![Box::new(Add(10)), Box::new(Add(-3))]); + Chain::new(vec![Box::new(Add(7)), Box::new(Add(3))]); let result = chain.traverse(Result(0)); - assert_eq!(result, Chained(Result(7))); + assert_eq!(result, Next(Result(10))); } #[test] @@ -86,6 +86,6 @@ mod test { let mut chain: Chain = Chain::new(vec![Box::new(Add(80)), Box::new(Add(30)), Box::new(Add(1))]); let result = chain.traverse(Result(0)); - assert_eq!(result, EarlyExit(Result(80))); + assert_eq!(result, Done(Result(80))); } } diff --git a/lychee-lib/src/client.rs b/lychee-lib/src/client.rs index 4f61016..88c1839 100644 --- a/lychee-lib/src/client.rs +++ b/lychee-lib/src/client.rs @@ -37,7 +37,7 @@ use typed_builder::TypedBuilder; use crate::{ chain::{ Chain, - ChainResult::{Chained, EarlyExit}, + ChainResult::{Next, Done}, RequestChain, }, filter::{Excludes, Filter, Includes}, @@ -676,8 +676,8 @@ impl Client { let result = request_chain.traverse(request); match result { - EarlyExit(status) => status, - Chained(r) => match self.reqwest_client.execute(r).await { + Done(status) => status, + Next(r) => match self.reqwest_client.execute(r).await { Ok(ref response) => Status::new(response, self.accepted.clone()), Err(e) => e.into(), }, @@ -1121,8 +1121,8 @@ mod tests { struct ExampleHandler(); impl Chainable for ExampleHandler { - fn handle(&mut self, _: Request) -> ChainResult { - ChainResult::EarlyExit(Status::Excluded) + fn chain(&mut self, _: Request) -> ChainResult { + ChainResult::Done(Status::Excluded) } } diff --git a/lychee-lib/src/quirks/mod.rs b/lychee-lib/src/quirks/mod.rs index fcfb5bf..0b177d7 100644 --- a/lychee-lib/src/quirks/mod.rs +++ b/lychee-lib/src/quirks/mod.rs @@ -91,8 +91,8 @@ impl Quirks { } impl Chainable for Quirks { - fn handle(&mut self, input: Request) -> ChainResult { - ChainResult::Chained(self.apply(input)) + fn chain(&mut self, input: Request) -> ChainResult { + ChainResult::Next(self.apply(input)) } } diff --git a/lychee-lib/src/types/basic_auth/credentials.rs b/lychee-lib/src/types/basic_auth/credentials.rs index ed10511..87c17da 100644 --- a/lychee-lib/src/types/basic_auth/credentials.rs +++ b/lychee-lib/src/types/basic_auth/credentials.rs @@ -74,10 +74,10 @@ impl BasicAuthCredentials { } impl Chainable for BasicAuthCredentials { - fn handle(&mut self, mut request: Request) -> ChainResult { + fn chain(&mut self, mut request: Request) -> ChainResult { request .headers_mut() .append(AUTHORIZATION, self.to_authorization().0.encode()); - ChainResult::Chained(request) + ChainResult::Next(request) } }