[−][src]Trait stringedits::Edit
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 Splitsfn 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 Transposesfn 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 Replacesfn 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 Insertsfn 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 Deletionsfn 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 Dist1Editsfn 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 Dist2Editsfn 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