From 7c6298ca500a7440ffdd9444dbca336c5fd01862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 19 Apr 2023 13:32:09 +0200 Subject: [PATCH] ScanNodes: Remove _with_context methods, make them the default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/element.rs | 48 +++++++++++++----------------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/src/element.rs b/src/element.rs index 65cf125..00adbfd 100644 --- a/src/element.rs +++ b/src/element.rs @@ -143,18 +143,7 @@ struct ScanNodes<'a, T: Debug> { } impl<'a> ScanNodes<'a, NonStrictComparison> { - fn new(nodes: Vec) -> ScanNodes<'a, NonStrictComparison> { - Self { - nodes, - context: None, - _strict: PhantomData, - } - } - - fn new_with_context( - nodes: Vec, - context: Option<&'a Context>, - ) -> ScanNodes<'a, NonStrictComparison> { + fn new(nodes: Vec, context: Option<&'a Context>) -> ScanNodes<'a, NonStrictComparison> { Self { nodes, context, @@ -164,15 +153,7 @@ impl<'a> ScanNodes<'a, NonStrictComparison> { } impl<'a> ScanNodes<'a, StrictComparison> { - fn new_strict(nodes: Vec) -> ScanNodes<'a, StrictComparison> { - Self { - nodes, - context: None, - _strict: PhantomData, - } - } - - fn new_strict_with_context( + fn new_strict( nodes: Vec, context: Option<&'a Context>, ) -> ScanNodes<'a, StrictComparison> { @@ -317,14 +298,11 @@ impl<'a, 'b> PartialEq<&Element> for ScanElement<'a, 'b> { _ => (), } - let nodes = ScanNodes::new_strict_with_context( - self.elem.nodes().cloned().collect(), - self.context, - ); + let nodes = + ScanNodes::new_strict(self.elem.nodes().cloned().collect(), self.context); nodes == onodes } else { - let nodes = - ScanNodes::new_with_context(self.elem.nodes().cloned().collect(), self.context); + let nodes = ScanNodes::new(self.elem.nodes().cloned().collect(), self.context); nodes == onodes } } else { @@ -347,12 +325,12 @@ mod tests { let elem1 = Node::Element(Element::from_str("").unwrap()); assert_eq!( - ScanNodes::new_strict(vec![elem1.clone()]), + ScanNodes::new_strict(vec![elem1.clone()], None), vec![elem1.clone()], ); assert_ne!( - ScanNodes::new_strict(vec![text1.clone()]), + ScanNodes::new_strict(vec![text1.clone()], None), vec![text2.clone()], ); } @@ -364,32 +342,32 @@ mod tests { let elem1 = Node::Element(Element::from_str("").unwrap()); assert_eq!( - ScanNodes::new_strict(vec![elem1.clone()]), + ScanNodes::new_strict(vec![elem1.clone()], None), vec![elem1.clone()], ); assert_eq!( - ScanNodes::new_strict(vec![text1.clone(), elem1.clone(), text2.clone()]), + ScanNodes::new_strict(vec![text1.clone(), elem1.clone(), text2.clone()], None), vec![elem1.clone()], ); assert_eq!( - ScanNodes::new_strict(vec![text1.clone(), elem1.clone()]), + ScanNodes::new_strict(vec![text1.clone(), elem1.clone()], None), vec![elem1.clone(), text2.clone()], ); assert_eq!( - ScanNodes::new_strict(vec![elem1.clone(), text1.clone(), elem1.clone()]), + ScanNodes::new_strict(vec![elem1.clone(), text1.clone(), elem1.clone()], None), vec![elem1.clone(), elem1.clone()], ); assert_ne!( - ScanNodes::new_strict(vec![elem1.clone(), text1.clone(), elem1.clone()]), + ScanNodes::new_strict(vec![elem1.clone(), text1.clone(), elem1.clone()], None), vec![elem1.clone()], ); assert_ne!( - ScanNodes::new_strict(vec![Node::Text(String::from("\n\tfoo\n"))]), + ScanNodes::new_strict(vec![Node::Text(String::from("\n\tfoo\n"))], None), vec![Node::Text(String::from("\n\tfoo"))], ); }