pub trait StringEstimation {
// Required method
fn estimate(&self, pattern: impl AsRef<str>) -> Closeness;
}Expand description
An extension trait for strings that estimates the distance between two strings.
Required Methods§
Sourcefn estimate(&self, pattern: impl AsRef<str>) -> Closeness
fn estimate(&self, pattern: impl AsRef<str>) -> Closeness
Estimates the similarity between two strings.
The returned Closeness object represents the similarity between
the provided string and the specified pattern in terms of percentage,
with fractional precision. A value of “100%” (Closeness::one) means
that the string fully matches the pattern.
use ad_astra::analysis::{Closeness, StringEstimation};
assert_eq!("foo".estimate("foo"), Closeness::one());
assert_eq!("foo".estimate("aaa"), Closeness::zero());
println!("{}", "foo".estimate("Foo")); // ~ 66%
println!("{}", "Bra".estimate("bar")); // ~ 33%Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".