From 92690c10d5798e4740b8d38be0fab6850c29aaf1 Mon Sep 17 00:00:00 2001 From: tison Date: Mon, 8 Dec 2025 14:42:55 +0800 Subject: [PATCH 1/3] refactor: rename or combinator to chain Signed-off-by: tison --- traversable/src/combinator.rs | 21 ++++++++++----------- traversable/tests/test_combinator.rs | 8 ++++---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/traversable/src/combinator.rs b/traversable/src/combinator.rs index 8ddf897..e453dba 100644 --- a/traversable/src/combinator.rs +++ b/traversable/src/combinator.rs @@ -69,16 +69,16 @@ pub trait VisitorExt: Visitor { /// }); /// /// // v1 runs first, then v2. - /// let mut combined = v1.or(v2); + /// let mut combined = v1.chain(v2); /// data.traverse(&mut combined); /// # } /// ``` - fn or(self, other: V) -> OrVisitor + fn chain(self, other: V) -> ChainVisitor where Self: Sized, V: Visitor, { - OrVisitor { + ChainVisitor { visitor1: self, visitor2: other, } @@ -136,19 +136,19 @@ pub trait VisitorMutExt: VisitorMut { /// ControlFlow::<()>::Continue(()) /// }); /// - /// let mut combined = v1.or(v2); + /// let mut combined = v1.chain(v2); /// data.traverse_mut(&mut combined); /// /// assert_eq!(data.foo.0, 2); /// assert_eq!(data.bar.0, 4); /// # } /// ``` - fn or(self, other: V) -> OrVisitor + fn chain(self, other: V) -> ChainVisitor where Self: Sized, V: VisitorMut, { - OrVisitor { + ChainVisitor { visitor1: self, visitor2: other, } @@ -159,14 +159,13 @@ impl VisitorMutExt for V {} /// A visitor that runs two visitors in sequence. /// -/// This struct is created by the [`or`](VisitorExt::or) method on [`VisitorExt`] or -/// [`VisitorMutExt`]. -pub struct OrVisitor { +/// This struct is created by the `chain` method on [`VisitorExt`] or [`VisitorMutExt`]. +pub struct ChainVisitor { visitor1: V1, visitor2: V2, } -impl Visitor for OrVisitor +impl Visitor for ChainVisitor where V1: Visitor, V2: Visitor, @@ -184,7 +183,7 @@ where } } -impl VisitorMut for OrVisitor +impl VisitorMut for ChainVisitor where V1: VisitorMut, V2: VisitorMut, diff --git a/traversable/tests/test_combinator.rs b/traversable/tests/test_combinator.rs index f53125c..16ffe27 100644 --- a/traversable/tests/test_combinator.rs +++ b/traversable/tests/test_combinator.rs @@ -86,7 +86,7 @@ fn test_visitor_or() { break_on: None, }; - let mut combined = v1.or(v2); + let mut combined = v1.chain(v2); let result = data.traverse(&mut combined); assert!(result.is_continue()); @@ -126,7 +126,7 @@ fn test_visitor_or_break_v1() { break_on: None, }; - let mut combined = v1.or(v2); + let mut combined = v1.chain(v2); let result = data.traverse(&mut combined); assert_eq!(result, ControlFlow::Break(2)); @@ -161,7 +161,7 @@ fn test_visitor_or_break_v2() { break_on: Some(2), }; - let mut combined = v1.or(v2); + let mut combined = v1.chain(v2); let result = data.traverse(&mut combined); assert_eq!(result, ControlFlow::Break(2)); @@ -201,7 +201,7 @@ fn test_visitor_mut_or() { let v1 = MutVisitor { val_multiplier: 2 }; let v2 = MutVisitor { val_multiplier: 3 }; - let mut combined = v1.or(v2); + let mut combined = v1.chain(v2); let result = data.traverse_mut(&mut combined); assert!(result.is_continue()); From 3cd8a4041f40a4a46b4ef102442de42700cd20cb Mon Sep 17 00:00:00 2001 From: tison Date: Mon, 8 Dec 2025 14:50:44 +0800 Subject: [PATCH 2/3] name Signed-off-by: tison --- traversable/src/combinator.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/traversable/src/combinator.rs b/traversable/src/combinator.rs index e453dba..94222da 100644 --- a/traversable/src/combinator.rs +++ b/traversable/src/combinator.rs @@ -73,12 +73,12 @@ pub trait VisitorExt: Visitor { /// data.traverse(&mut combined); /// # } /// ``` - fn chain(self, other: V) -> ChainVisitor + fn chain(self, other: V) -> Chain where Self: Sized, V: Visitor, { - ChainVisitor { + Chain { visitor1: self, visitor2: other, } @@ -143,12 +143,12 @@ pub trait VisitorMutExt: VisitorMut { /// assert_eq!(data.bar.0, 4); /// # } /// ``` - fn chain(self, other: V) -> ChainVisitor + fn chain(self, other: V) -> Chain where Self: Sized, V: VisitorMut, { - ChainVisitor { + Chain { visitor1: self, visitor2: other, } @@ -160,12 +160,12 @@ impl VisitorMutExt for V {} /// A visitor that runs two visitors in sequence. /// /// This struct is created by the `chain` method on [`VisitorExt`] or [`VisitorMutExt`]. -pub struct ChainVisitor { +pub struct Chain { visitor1: V1, visitor2: V2, } -impl Visitor for ChainVisitor +impl Visitor for Chain where V1: Visitor, V2: Visitor, @@ -183,7 +183,7 @@ where } } -impl VisitorMut for ChainVisitor +impl VisitorMut for Chain where V1: VisitorMut, V2: VisitorMut, From 7ea3dd5fb5a51175bd6a77ab4e08405ec66560e2 Mon Sep 17 00:00:00 2001 From: tison Date: Mon, 8 Dec 2025 14:54:34 +0800 Subject: [PATCH 3/3] links Signed-off-by: tison --- traversable/src/combinator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traversable/src/combinator.rs b/traversable/src/combinator.rs index 94222da..449ebee 100644 --- a/traversable/src/combinator.rs +++ b/traversable/src/combinator.rs @@ -159,7 +159,7 @@ impl VisitorMutExt for V {} /// A visitor that runs two visitors in sequence. /// -/// This struct is created by the `chain` method on [`VisitorExt`] or [`VisitorMutExt`]. +/// This struct is created by [`VisitorExt::chain`] or [`VisitorMutExt::chain`]. pub struct Chain { visitor1: V1, visitor2: V2,