sqlload 0.37.0

SQL data loading tooling.
1
2
3
4
5
6
7
8
9
10
11
12
13
//! The closest candidate to a misspelt name.

use crate::similar_names::_helpers::distance::edit_distance;

/// The candidate with the smallest edit distance to `name`, if there are any candidates.
pub fn nearest_name<'a>(
    name: &str,
    candidates: impl IntoIterator<Item = &'a str>,
) -> Option<&'a str> {
    candidates
        .into_iter()
        .min_by_key(|candidate| edit_distance(name, candidate))
}