Skip to main content

did_you_mean

Function did_you_mean 

Source
pub(crate) fn did_you_mean<I, S>(needle: &str, candidates: I) -> Vec<String>
where I: IntoIterator<Item = S>, S: AsRef<str>,
Expand description

Return up to MAX_DID_YOU_MEAN closest names from candidates to needle, sorted by Damerau-Levenshtein distance ascending. Names whose distance exceeds max(2, needle.len() / 3) are filtered out so unrelated matches don’t surface as quick fixes.

Allocations only happen for surviving candidates, so passing a borrowed slice (e.g. pool.iter()) is cheap even when the pool has thousands of names.