Switch to more generic implementation.

This commit is contained in:
Tom Alexander
2023-10-06 16:03:41 -04:00
parent 3da52a0826
commit c7dbe596b3
3 changed files with 11 additions and 33 deletions

View File

@@ -23,35 +23,10 @@ pub(crate) fn compare_noop<'b, 's, 'x>(
Ok(None)
}
pub(crate) fn compare_property_quoted_string_required_value<'b, 's, 'x>(
pub(crate) fn compare_property_quoted_string<'b, 's, 'x, R, RG: Fn(R) -> Option<&'s str>>(
emacs: &'b Token<'s>,
emacs_field: &'x str,
rust_value: &'s str,
) -> Result<Option<(DiffStatus, Option<String>)>, Box<dyn std::error::Error>> {
let value = get_property_quoted_string(emacs, emacs_field)?;
if value.as_ref().map(String::as_str) != Some(rust_value) {
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<
'b,
's,
'x,
R,
RV: Debug + for<'a> PartialEq<Option<&'a str>>,
RG: Fn(R) -> RV,
>(
emacs: &'b Token<'s>,
emacs_field: &'x str,
rust_node: R,
emacs_field: &'x str,
rust_value_getter: RG,
) -> Result<Option<(DiffStatus, Option<String>)>, Box<dyn std::error::Error>> {
let value = get_property_quoted_string(emacs, emacs_field)?;