From 7e21caf9b08e3a88df4649325071aace94d3fcbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20Gro=C3=9F?= Date: Thu, 8 Jan 2026 07:17:18 +0100 Subject: [PATCH] Refactor: Modernize codebase with edition 2024 and improve match patterns --- Cargo.toml | 2 +- src/canonicalize.rs | 4 ++-- src/interface.rs | 2 +- src/speech.rs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d8ba6280..bf013e23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ description = "MathCAT: Math Capable Assistive Technology ('Speech and braille f repository = "https://github.com/NSoiffer/MathCAT" homepage = "https://nsoiffer.github.io/MathCAT/" documentation = "https://nsoiffer.github.io/MathCAT/" -edition = "2018" +edition = "2024" exclude = ["src/main.rs", "docs", "PythonScripts"] # should have "Rules/", but then one can't run build.rs to build the zip file diff --git a/src/canonicalize.rs b/src/canonicalize.rs index 52cd0b6b..7dadd054 100644 --- a/src/canonicalize.rs +++ b/src/canonicalize.rs @@ -382,7 +382,7 @@ pub fn replace_children<'a>(mathml: Element<'a>, replacements: Vec>) pub fn get_presentation_element(element: Element) -> (usize, Element) { assert_eq!(name(element), "semantics"); let children = element.children(); - if let Some( (i, child) ) = children.iter().enumerate().find(|(_, &child)| + if let Some( (i, child) ) = children.iter().enumerate().find(|&(_, &child)| if let Some(encoding) = as_element(child).attribute_value("encoding") { encoding == "MathML-Presentation" } else { @@ -1502,7 +1502,7 @@ impl CanonicalizeContext { let n = children.len(); let i_mprescripts = if let Some((i,_)) = children.iter().enumerate() - .find(|(_,&el)| name(as_element(el)) == "mprescripts") { i } else { n }; + .find(|&(_,&el)| name(as_element(el)) == "mprescripts") { i } else { n }; let has_misplaced_mprescripts = i_mprescripts & 1 == 0; // should be first, third, ... child let mut has_proper_number_of_children = if i_mprescripts == n { n & 1 == 0} else { n & 1 != 0 }; // should be odd else even # if has_misplaced_mprescripts || !has_proper_number_of_children || has_none_none_script_pair(&children) { diff --git a/src/interface.rs b/src/interface.rs index 665e1e0d..8611f443 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -1139,7 +1139,7 @@ mod tests { fn can_recover_from_invalid_set_rules_dir() { use std::env; // MathCAT will check the env var "MathCATRulesDir" as an override, so the following test might succeed if we don't override the env var - env::set_var("MathCATRulesDir", "MathCATRulesDir"); + unsafe { env::set_var("MathCATRulesDir", "MathCATRulesDir"); } assert!(set_rules_dir("someInvalidRulesDir".to_string()).is_err()); assert!( set_rules_dir(super::super::abs_rules_dir_path()).is_ok(), diff --git a/src/speech.rs b/src/speech.rs index 091528db..c460810c 100644 --- a/src/speech.rs +++ b/src/speech.rs @@ -1895,14 +1895,14 @@ impl UnicodeDef { fn substitute_ch(yaml: &Yaml, ch: &str) -> Yaml { return match yaml { - Yaml::Array(ref v) => { + Yaml::Array(v) => { Yaml::Array( v.iter() .map(|e| substitute_ch(e, ch)) .collect::>() ) }, - Yaml::Hash(ref h) => { + Yaml::Hash(h) => { Yaml::Hash( h.iter() .map(|(key,val)| (key.clone(), substitute_ch(val, ch)) )