From 1e02dd2d1fa8bad307ccf7688a4f42e5f00026be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Fri, 21 Apr 2023 17:33:16 +0200 Subject: [PATCH] ScanElement now owns the Element MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/element.rs | 52 +++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/element.rs b/src/element.rs index abb845e..99c64ee 100644 --- a/src/element.rs +++ b/src/element.rs @@ -85,7 +85,7 @@ impl<'a> PartialEq for ScanNode<'a> { match (&self.node, other) { (Node::Text(text1), Node::Text(text2)) => text1 == text2, (Node::Element(elem1), Node::Element(elem2)) => { - ScanElement::new(&elem1).with_context(self.context) == elem2 + ScanElement::new(elem1.clone()).with_context(self.context) == elem2 } _ => false, } @@ -202,12 +202,12 @@ impl<'a> PartialEq> for ScanNodes<'a, NonStrictComparison> { /// changes the way the comparison is done. /// Also uses the custom ScanNode implementation. #[derive(Debug, Clone)] -pub struct ScanElement<'a, 'b> { - elem: &'a Element, - context: Option<&'b Context>, +pub struct ScanElement<'a> { + elem: Element, + context: Option<&'a Context>, } -impl<'a, 'b> Deref for ScanElement<'a, 'b> { +impl<'a> Deref for ScanElement<'a> { type Target = Element; fn deref(&self) -> &Self::Target { @@ -215,8 +215,8 @@ impl<'a, 'b> Deref for ScanElement<'a, 'b> { } } -impl<'a> ScanElement<'a, 'static> { - pub fn new(elem: &'a Element) -> ScanElement { +impl<'a> ScanElement<'a> { + pub fn new(elem: Element) -> ScanElement<'a> { Self { elem, context: None, @@ -224,8 +224,8 @@ impl<'a> ScanElement<'a, 'static> { } } -impl<'a, 'b> ScanElement<'a, 'b> { - pub fn with_context(self, context: Option<&'b Context>) -> ScanElement<'a, 'b> { +impl<'a> ScanElement<'a> { + pub fn with_context(self, context: Option<&'a Context>) -> ScanElement<'a> { Self { elem: self.elem, context, @@ -233,7 +233,7 @@ impl<'a, 'b> ScanElement<'a, 'b> { } } -impl<'a, 'b> PartialEq<&Element> for ScanElement<'a, 'b> { +impl<'a> PartialEq<&Element> for ScanElement<'a> { fn eq(&self, other: &&Element) -> bool { let self_ns = self.elem.ns(); if self.elem.name() == other.name() && self_ns == other.ns() { @@ -375,7 +375,7 @@ mod tests { .parse() .unwrap(); let elem2: Element = "".parse().unwrap(); - let scan1 = ScanElement::new(&elem1); + let scan1 = ScanElement::new(elem1); assert_eq!(scan1, &elem2); } @@ -388,7 +388,7 @@ mod tests { let elem2: Element = "\n\tfoo\t" .parse() .unwrap(); - let scan1 = ScanElement::new(&elem1); + let scan1 = ScanElement::new(elem1); assert_ne!(scan1, &elem2); } @@ -396,7 +396,7 @@ mod tests { #[test] fn compare_element_strict_attributes_success() { let elem1: Element = "".parse().unwrap(); - let scan1 = ScanElement::new(&elem1); + let scan1 = ScanElement::new(elem1.clone()); assert_eq!(scan1, &elem1); @@ -410,7 +410,7 @@ mod tests { " .parse() .unwrap(); - let scan2 = ScanElement::new(&elem2); + let scan2 = ScanElement::new(elem2); assert_eq!(scan2, &elem3); } @@ -419,7 +419,7 @@ mod tests { fn compare_element_strict_attributes_failure() { let elem1: Element = "".parse().unwrap(); let elem2: Element = "".parse().unwrap(); - let scan1 = ScanElement::new(&elem1); + let scan1 = ScanElement::new(elem1); assert_ne!(scan1, &elem2); } @@ -443,7 +443,7 @@ mod tests { " .parse() .unwrap(); - let scan1 = ScanElement::new(&elem1); + let scan1 = ScanElement::new(elem1); assert_eq!(scan1, &elem2); } @@ -464,7 +464,7 @@ mod tests { " .parse() .unwrap(); - let scan1 = ScanElement::new(&elem1); + let scan1 = ScanElement::new(elem1); assert_ne!(scan1, &elem2); } @@ -474,7 +474,7 @@ mod tests { let elem1: Element = "" .parse() .unwrap(); - let scan1 = ScanElement::new(&elem1); + let scan1 = ScanElement::new(elem1.clone()); assert_eq!(scan1, &elem1); @@ -488,7 +488,7 @@ mod tests { " .parse() .unwrap(); - let scan2 = ScanElement::new(&elem2); + let scan2 = ScanElement::new(elem2); assert_eq!(scan2, &elem3); } @@ -499,7 +499,7 @@ mod tests { .parse() .unwrap(); let elem2: Element = "".parse().unwrap(); - let scan1 = ScanElement::new(&elem1); + let scan1 = ScanElement::new(elem1); assert_ne!(scan1, &elem2); @@ -513,7 +513,7 @@ mod tests { " .parse() .unwrap(); - let scan2 = ScanElement::new(&elem2); + let scan2 = ScanElement::new(elem2); assert_ne!(scan2, &elem3); } @@ -524,7 +524,7 @@ mod tests { .parse() .unwrap(); let elem2: Element = "".parse().unwrap(); - let scan1 = ScanElement::new(&elem1); + let scan1 = ScanElement::new(elem1); assert_eq!(scan1, &elem2); @@ -533,7 +533,7 @@ mod tests { let elem4: Element = "" .parse() .unwrap(); - let scan3 = ScanElement::new(&elem3); + let scan3 = ScanElement::new(elem3); assert_eq!(scan3, &elem4); } @@ -550,7 +550,7 @@ mod tests { " .parse() .unwrap(); - let scan2 = ScanElement::new(&elem2); + let scan2 = ScanElement::new(elem2); assert_ne!(scan2, &elem3); } @@ -567,7 +567,7 @@ mod tests { " .parse() .unwrap(); - let scan1 = ScanElement::new(&elem1); + let scan1 = ScanElement::new(elem1); assert_ne!(scan1, &elem2); } @@ -578,7 +578,7 @@ mod tests { .parse() .unwrap(); let elem2: Element = "".parse().unwrap(); - let scan1 = ScanElement::new(&elem1); + let scan1 = ScanElement::new(elem1); assert_eq!(scan1, &elem2); }