[][src]Trait stringedits::Edit

pub trait Edit: AsRef<str> {
    fn splits(&self) -> Splits { ... }
fn transposes(&self) -> Transposes { ... }
fn replaces(&self) -> Replaces { ... }
fn inserts(&self) -> Inserts { ... }
fn deletions(&self) -> Deletions { ... }
fn dist1edits(&self) -> Dist1Edits { ... }
fn dist2edits(&self) -> Dist2Edits { ... } }

The Edit trait provides access to a number of iterators for single-and-double character edits of a string. It is implemented for any type that implements AsRef<str>.

Provided methods

Important traits for Splits
fn splits(&self) -> Splits

create an iterator over all the splits at a single position of a word.

let want: HashSet<(String, String)> = vec![("", "foo"), ("f", "oo"), ("fo", "o"), ("foo", "")]
    .into_iter()
    .map(|(a, b)| (a.to_string(), b.to_string()))
    .collect();
let got: HashSet<(String, String)> = "foo".splits().collect();
assert_eq!(want, got);

Important traits for Transposes
fn transposes(&self) -> Transposes

create an iterator over all distance-1 transpositions of a word

let got: HashSet<String> = "bar".replaces().collect();
assert!(got.contains("bzr"));
assert!(got.contains("xar"));

Important traits for Replaces
fn replaces(&self) -> Replaces

create an iterator over all distance-1 replacements with a lowercase ASCII letter ('b'a..=b'z')

let got: HashSet<String> = "bar".replaces().collect();
assert!(got.contains("bzr"));
assert!(got.contains("xar"));

Important traits for Inserts
fn inserts(&self) -> Inserts

create an iterator over all distance-1 insertions of a lowercase ASCII letter ('b'a..=b'z')

let got: HashSet<String> = "bar".inserts().collect();
assert!(got.contains("abar"));
assert!(got.contains("bbar"));
assert!(got.contains("bacr"));
assert!(got.contains("bard"));

Important traits for Deletions
fn deletions(&self) -> Deletions

create an iterator over all single-character deletions of a word

let got: HashSet<String> = "bar".deletions().collect();
let mut want: HashSet<String> = vec!["ar", "ba", "br"].into_iter().map(|s| s.to_string()).collect();
assert_eq!(want, got);

Important traits for Dist1Edits
fn dist1edits(&self) -> Dist1Edits

create an iterator over all distance-1 edits of the string; that is, the transposes, replacements, insertions, and deletions

let got: HashSet<String> = "bar".dist1edits().collect();
assert!(got.contains("br")); // deletion
assert!(got.contains("bbar")); // addition
assert!(got.contains("bra")); // transposition
assert!(got.contains("baz")); // substitution

Important traits for Dist2Edits
fn dist2edits(&self) -> Dist2Edits

create an iterator over all distance-2 edits of the string; that is, choose two (with replacement) from transposition, replacement with b'a..=b'z', insertion of b'a'..=b'z', and deletion

let got: HashSet<String> = "bar".dist2edits().collect();
assert!(got.contains("b")); // deletion 2
assert!(got.contains("bbra")); // addition and substitution
assert!(got.contains("rba")); // transposition 2
assert!(got.contains("bz")); // substitution and deletion
Loading content...

Implementors

impl<T: AsRef<str>> Edit for T[src]

Important traits for Splits
fn splits(&self) -> Splits[src]

Important traits for Transposes
fn transposes(&self) -> Transposes[src]

Important traits for Replaces
fn replaces(&self) -> Replaces[src]

Important traits for Inserts
fn inserts(&self) -> Inserts[src]

Important traits for Deletions
fn deletions(&self) -> Deletions[src]

Important traits for Dist1Edits
fn dist1edits(&self) -> Dist1Edits[src]

Important traits for Dist2Edits
fn dist2edits(&self) -> Dist2Edits[src]

Loading content...