Crate fuzzy_cmp

Crate fuzzy_cmp 

Source
Expand description

githubcrates-iodocs-rs

§Fuzzy Compare

Rust library for fuzzy string matching using Levenshtein distance. Returns results with similarity coefficient (0.0 = 0%, 1.0 = 100%) sorted from best to worst match.

§Features:

  • Performance: O(n × L²) where L is average string length.
  • Case-insensitive: With automatic lowercase conversion.
  • Safe: Handles empty strings, division by zero.
  • Generic: Works with any Clone type via closure.
  • Sorting: Descending sort by coefficient.

§Examples:

#[derive(Debug, Clone, Eq, PartialEq)]
struct Person {
    name: String,
    age: u32,
}

fn main() {
    let people = vec![
        Person { name: "Alice".to_owned(), age: 30 },
        Person { name: "Bob".to_owned(), age: 25 },
        Person { name: "Alicia".to_owned(), age: 28 },
    ];

    let results = fuzzy_cmp::search_filter(&people, "Ali", 0.6, |p: &Person| &p.name);
    let best = &results[0];
    
    println!("Best result: {best:?}");
    assert_eq!(best.1, Person { name: "Alice".to_owned(), age: 30 });
}

§Licensing:

Distributed under the MIT license.

§Feedback:

You can find me here, also see my channel. I welcome your suggestions and feedback!

Copyright (c) 2025 Bulat Sh. (fuderis)

Re-exports§

pub use error::StdResult;
pub use error::Result;
pub use error::Error;
pub use fuzzy::*;

Modules§

error
fuzzy
prelude