Skip to main content

closest_match

Function closest_match 

Source
pub fn closest_match<'a, I>(input: &str, candidates: I) -> Option<&'a str>
where I: IntoIterator<Item = &'a str>,
Expand description

Find the closest candidate to input when it is plausibly a typo.

Returns the best match when the Levenshtein distance is at most 2 AND the input is long enough that the match is not coincidental (input.len() / 2 > distance). Returns None when no candidate clears the bar so callers stay silent on completely novel strings rather than emitting a misleading suggestion.

Input is lowercased before comparison; callers should pass canonical-case candidates (kebab-case for rule names, original-case for package names).