From 4716e1ce5bb2cc6514098b4901d795cc795d8cd8 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 6 Oct 2023 19:49:06 -0400 Subject: [PATCH] Switch to using AsRef to make compare_property_quoted_string generic. --- src/compare/compare_field.rs | 31 +++++++++---------------------- src/compare/diff.rs | 7 +++---- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/compare/compare_field.rs b/src/compare/compare_field.rs index 56cc6d8..f4af14d 100644 --- a/src/compare/compare_field.rs +++ b/src/compare/compare_field.rs @@ -56,7 +56,14 @@ pub(crate) fn compare_property_always_nil<'b, 's, 'x, R, RG>( } } -pub(crate) fn compare_property_quoted_string<'b, 's, 'x, R, RG: Fn(R) -> Option<&'s str>>( +pub(crate) fn compare_property_quoted_string< + 'b, + 's, + 'x, + R, + RV: AsRef + std::fmt::Debug, + RG: Fn(R) -> Option, +>( emacs: &'b Token<'s>, rust_node: R, emacs_field: &'x str, @@ -64,27 +71,7 @@ pub(crate) fn compare_property_quoted_string<'b, 's, 'x, R, RG: Fn(R) -> Option< ) -> Result)>, Box> { let value = get_property_quoted_string(emacs, emacs_field)?; let rust_value = rust_value_getter(rust_node); - if rust_value != value.as_ref().map(String::as_str) { - let this_status = DiffStatus::Bad; - let message = Some(format!( - "{} mismatch (emacs != rust) {:?} != {:?}", - emacs_field, value, rust_value - )); - Ok(Some((this_status, message))) - } else { - Ok(None) - } -} - -pub(crate) fn compare_property_quoted_string_owned<'b, 's, 'x, R, RG: Fn(R) -> Option>( - emacs: &'b Token<'s>, - rust_node: R, - emacs_field: &'x str, - rust_value_getter: RG, -) -> Result)>, Box> { - let value = get_property_quoted_string(emacs, emacs_field)?; - let rust_value = rust_value_getter(rust_node); - if rust_value != value { + if rust_value.as_ref().map(|s| s.as_ref()) != value.as_ref().map(String::as_str) { let this_status = DiffStatus::Bad; let message = Some(format!( "{} mismatch (emacs != rust) {:?} != {:?}", diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 5114e81..016bb91 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -6,7 +6,6 @@ use std::collections::HashSet; use super::compare_field::compare_identity; use super::compare_field::compare_property_always_nil; use super::compare_field::compare_property_quoted_string; -use super::compare_field::compare_property_quoted_string_owned; use super::compare_field::compare_property_unquoted_atom; use super::elisp_fact::ElispFact; use super::elisp_fact::GetElispFact; @@ -2786,7 +2785,7 @@ fn compare_regular_link<'b, 's>( ( EmacsField::Required(":path"), |r| Some(r.get_path()), - compare_property_quoted_string_owned + compare_property_quoted_string ), ( EmacsField::Required(":format"), @@ -2796,7 +2795,7 @@ fn compare_regular_link<'b, 's>( ( EmacsField::Required(":raw-link"), |r| Some(r.get_raw_link()), - compare_property_quoted_string_owned + compare_property_quoted_string ), ( EmacsField::Required(":application"), @@ -2806,7 +2805,7 @@ fn compare_regular_link<'b, 's>( ( EmacsField::Required(":search-option"), |r| r.get_search_option(), - compare_property_quoted_string_owned + compare_property_quoted_string ) )? { this_status = new_status;