pub struct Changeset {
pub diffs: Vec<Difference>,
pub split: String,
pub distance: i128,
}Expand description
The information about a full changeset
Fields§
§diffs: Vec<Difference>An ordered vector of Difference objects, corresponding
to the differences within the text
split: StringThe split used when creating the Changeset
Common splits are "" for char-level, " " for word-level and "\n" for line-level.
distance: i128The edit distance of the Changeset
Implementations§
Source§impl Changeset
impl Changeset
Sourcepub fn new(orig: &str, edit: &str, split: &str) -> Changeset
pub fn new(orig: &str, edit: &str, split: &str) -> Changeset
Calculates the edit distance and the changeset for two given strings. The first string is assumed to be the “original”, the second to be an edited version of the first. The third parameter specifies how to split the input strings, leading to a more or less exact comparison.
Common splits are "" for char-level, " " for word-level and "\n" for line-level.
Outputs the edit distance (how much the two strings differ) and a “changeset”, that is
a Vec containing Differences.
§Examples
use difference_rs::{Changeset, Difference};
let changeset = Changeset::new("test", "tent", "");
assert_eq!(changeset.diffs, vec![
Difference::Same("te".to_string()),
Difference::Rem("s".to_string()),
Difference::Add("n".to_string()),
Difference::Same("t".to_string())
]);Sourcepub fn new_multi(orig: &str, edit: &str, splits: &[&str]) -> ChangesetMulti
pub fn new_multi(orig: &str, edit: &str, splits: &[&str]) -> ChangesetMulti
Creates a Changeset with multiple possible splits.
The first string is assumed to be the “original”, the second to be an
edited version of the first. The third parameter specifies how to split
the input strings, leading to a more or less exact comparison.
Outputs the edit distance (how much the two strings differ), original string splits, edit string splits, a “changeset”, that is
a Vec containing Differences.
Obs: Splits are included inside the Difference vector, as it is the only way to correctly rebuild strings, which differs from
Changeset::new that all spaces are filled by a single split.
§Examples
use difference_rs::{Changeset, Difference};
let changeset = Changeset::new_multi(
"https://localhost:8080/path?query=value",
"https://myapi.com/api/path?query=asset",
&["://", "/", "?", "="],
);
assert_eq!(changeset.diffs, vec![
Difference::Same("https://".to_string()),
Difference::Rem("localhost:8080/".to_string()),
Difference::Add("myapi.com/api/".to_string()),
Difference::Same("path?query=".to_string()),
Difference::Rem("value".to_string()),
Difference::Add("asset".to_string()),
]);