Struct SequenceMatcher

Source
pub struct SequenceMatcher<'a, T: 'a + Sequence> { /* private fields */ }

Implementations§

Source§

impl<'a, T: Sequence> SequenceMatcher<'a, T>

Source

pub fn new<S>( first_sequence: &'a S, second_sequence: &'a S, ) -> SequenceMatcher<'a, T>
where S: AsRef<[T]> + ?Sized,

Examples found in repository?
examples/example.rs (line 50)
6fn main() {
7    // unified_diff
8    let first_text = "one two three four".split(" ").collect::<Vec<&str>>();
9    let second_text = "zero one tree four".split(" ").collect::<Vec<&str>>();
10    let diff = difflib::unified_diff(
11        &first_text,
12        &second_text,
13        "Original",
14        "Current",
15        "2005-01-26 23:30:50",
16        "2010-04-02 10:20:52",
17        3,
18    );
19    for line in &diff {
20        println!("{:?}", line);
21    }
22
23    //context_diff
24    let diff = difflib::context_diff(
25        &first_text,
26        &second_text,
27        "Original",
28        "Current",
29        "2005-01-26 23:30:50",
30        "2010-04-02 10:20:52",
31        3,
32    );
33    for line in &diff {
34        println!("{:?}", line);
35    }
36
37    //get_close_matches
38    let words = vec!["ape", "apple", "peach", "puppy"];
39    let result = difflib::get_close_matches("appel", words, 3, 0.6);
40    println!("{:?}", result);
41
42    //Differ examples
43    let differ = Differ::new();
44    let diff = differ.compare(&first_text, &second_text);
45    for line in &diff {
46        println!("{:?}", line);
47    }
48
49    //SequenceMatcher examples
50    let mut matcher = SequenceMatcher::new("one two three four", "zero one tree four");
51    let m = matcher.find_longest_match(0, 18, 0, 18);
52    println!("{:?}", m);
53    let all_matches = matcher.get_matching_blocks();
54    println!("{:?}", all_matches);
55    let opcode = matcher.get_opcodes();
56    println!("{:?}", opcode);
57    let grouped_opcodes = matcher.get_grouped_opcodes(2);
58    println!("{:?}", grouped_opcodes);
59    let ratio = matcher.ratio();
60    println!("{:?}", ratio);
61    matcher.set_seqs("aaaaa", "aaaab");
62    println!("{:?}", matcher.ratio());
63}
Source

pub fn set_is_junk(&mut self, is_junk: Option<fn(&T) -> bool>)

Source

pub fn set_seqs<S>(&mut self, first_sequence: &'a S, second_sequence: &'a S)
where S: AsRef<[T]> + ?Sized,

Examples found in repository?
examples/example.rs (line 61)
6fn main() {
7    // unified_diff
8    let first_text = "one two three four".split(" ").collect::<Vec<&str>>();
9    let second_text = "zero one tree four".split(" ").collect::<Vec<&str>>();
10    let diff = difflib::unified_diff(
11        &first_text,
12        &second_text,
13        "Original",
14        "Current",
15        "2005-01-26 23:30:50",
16        "2010-04-02 10:20:52",
17        3,
18    );
19    for line in &diff {
20        println!("{:?}", line);
21    }
22
23    //context_diff
24    let diff = difflib::context_diff(
25        &first_text,
26        &second_text,
27        "Original",
28        "Current",
29        "2005-01-26 23:30:50",
30        "2010-04-02 10:20:52",
31        3,
32    );
33    for line in &diff {
34        println!("{:?}", line);
35    }
36
37    //get_close_matches
38    let words = vec!["ape", "apple", "peach", "puppy"];
39    let result = difflib::get_close_matches("appel", words, 3, 0.6);
40    println!("{:?}", result);
41
42    //Differ examples
43    let differ = Differ::new();
44    let diff = differ.compare(&first_text, &second_text);
45    for line in &diff {
46        println!("{:?}", line);
47    }
48
49    //SequenceMatcher examples
50    let mut matcher = SequenceMatcher::new("one two three four", "zero one tree four");
51    let m = matcher.find_longest_match(0, 18, 0, 18);
52    println!("{:?}", m);
53    let all_matches = matcher.get_matching_blocks();
54    println!("{:?}", all_matches);
55    let opcode = matcher.get_opcodes();
56    println!("{:?}", opcode);
57    let grouped_opcodes = matcher.get_grouped_opcodes(2);
58    println!("{:?}", grouped_opcodes);
59    let ratio = matcher.ratio();
60    println!("{:?}", ratio);
61    matcher.set_seqs("aaaaa", "aaaab");
62    println!("{:?}", matcher.ratio());
63}
Source

pub fn set_first_seq<S>(&mut self, sequence: &'a S)
where S: AsRef<[T]> + ?Sized,

Source

pub fn set_second_seq<S>(&mut self, sequence: &'a S)
where S: AsRef<[T]> + ?Sized,

Source

pub fn find_longest_match( &self, first_start: usize, first_end: usize, second_start: usize, second_end: usize, ) -> Match

Examples found in repository?
examples/example.rs (line 51)
6fn main() {
7    // unified_diff
8    let first_text = "one two three four".split(" ").collect::<Vec<&str>>();
9    let second_text = "zero one tree four".split(" ").collect::<Vec<&str>>();
10    let diff = difflib::unified_diff(
11        &first_text,
12        &second_text,
13        "Original",
14        "Current",
15        "2005-01-26 23:30:50",
16        "2010-04-02 10:20:52",
17        3,
18    );
19    for line in &diff {
20        println!("{:?}", line);
21    }
22
23    //context_diff
24    let diff = difflib::context_diff(
25        &first_text,
26        &second_text,
27        "Original",
28        "Current",
29        "2005-01-26 23:30:50",
30        "2010-04-02 10:20:52",
31        3,
32    );
33    for line in &diff {
34        println!("{:?}", line);
35    }
36
37    //get_close_matches
38    let words = vec!["ape", "apple", "peach", "puppy"];
39    let result = difflib::get_close_matches("appel", words, 3, 0.6);
40    println!("{:?}", result);
41
42    //Differ examples
43    let differ = Differ::new();
44    let diff = differ.compare(&first_text, &second_text);
45    for line in &diff {
46        println!("{:?}", line);
47    }
48
49    //SequenceMatcher examples
50    let mut matcher = SequenceMatcher::new("one two three four", "zero one tree four");
51    let m = matcher.find_longest_match(0, 18, 0, 18);
52    println!("{:?}", m);
53    let all_matches = matcher.get_matching_blocks();
54    println!("{:?}", all_matches);
55    let opcode = matcher.get_opcodes();
56    println!("{:?}", opcode);
57    let grouped_opcodes = matcher.get_grouped_opcodes(2);
58    println!("{:?}", grouped_opcodes);
59    let ratio = matcher.ratio();
60    println!("{:?}", ratio);
61    matcher.set_seqs("aaaaa", "aaaab");
62    println!("{:?}", matcher.ratio());
63}
Source

pub fn get_matching_blocks(&mut self) -> Vec<Match>

Examples found in repository?
examples/example.rs (line 53)
6fn main() {
7    // unified_diff
8    let first_text = "one two three four".split(" ").collect::<Vec<&str>>();
9    let second_text = "zero one tree four".split(" ").collect::<Vec<&str>>();
10    let diff = difflib::unified_diff(
11        &first_text,
12        &second_text,
13        "Original",
14        "Current",
15        "2005-01-26 23:30:50",
16        "2010-04-02 10:20:52",
17        3,
18    );
19    for line in &diff {
20        println!("{:?}", line);
21    }
22
23    //context_diff
24    let diff = difflib::context_diff(
25        &first_text,
26        &second_text,
27        "Original",
28        "Current",
29        "2005-01-26 23:30:50",
30        "2010-04-02 10:20:52",
31        3,
32    );
33    for line in &diff {
34        println!("{:?}", line);
35    }
36
37    //get_close_matches
38    let words = vec!["ape", "apple", "peach", "puppy"];
39    let result = difflib::get_close_matches("appel", words, 3, 0.6);
40    println!("{:?}", result);
41
42    //Differ examples
43    let differ = Differ::new();
44    let diff = differ.compare(&first_text, &second_text);
45    for line in &diff {
46        println!("{:?}", line);
47    }
48
49    //SequenceMatcher examples
50    let mut matcher = SequenceMatcher::new("one two three four", "zero one tree four");
51    let m = matcher.find_longest_match(0, 18, 0, 18);
52    println!("{:?}", m);
53    let all_matches = matcher.get_matching_blocks();
54    println!("{:?}", all_matches);
55    let opcode = matcher.get_opcodes();
56    println!("{:?}", opcode);
57    let grouped_opcodes = matcher.get_grouped_opcodes(2);
58    println!("{:?}", grouped_opcodes);
59    let ratio = matcher.ratio();
60    println!("{:?}", ratio);
61    matcher.set_seqs("aaaaa", "aaaab");
62    println!("{:?}", matcher.ratio());
63}
Source

pub fn get_opcodes(&mut self) -> Vec<Opcode>

Examples found in repository?
examples/example.rs (line 55)
6fn main() {
7    // unified_diff
8    let first_text = "one two three four".split(" ").collect::<Vec<&str>>();
9    let second_text = "zero one tree four".split(" ").collect::<Vec<&str>>();
10    let diff = difflib::unified_diff(
11        &first_text,
12        &second_text,
13        "Original",
14        "Current",
15        "2005-01-26 23:30:50",
16        "2010-04-02 10:20:52",
17        3,
18    );
19    for line in &diff {
20        println!("{:?}", line);
21    }
22
23    //context_diff
24    let diff = difflib::context_diff(
25        &first_text,
26        &second_text,
27        "Original",
28        "Current",
29        "2005-01-26 23:30:50",
30        "2010-04-02 10:20:52",
31        3,
32    );
33    for line in &diff {
34        println!("{:?}", line);
35    }
36
37    //get_close_matches
38    let words = vec!["ape", "apple", "peach", "puppy"];
39    let result = difflib::get_close_matches("appel", words, 3, 0.6);
40    println!("{:?}", result);
41
42    //Differ examples
43    let differ = Differ::new();
44    let diff = differ.compare(&first_text, &second_text);
45    for line in &diff {
46        println!("{:?}", line);
47    }
48
49    //SequenceMatcher examples
50    let mut matcher = SequenceMatcher::new("one two three four", "zero one tree four");
51    let m = matcher.find_longest_match(0, 18, 0, 18);
52    println!("{:?}", m);
53    let all_matches = matcher.get_matching_blocks();
54    println!("{:?}", all_matches);
55    let opcode = matcher.get_opcodes();
56    println!("{:?}", opcode);
57    let grouped_opcodes = matcher.get_grouped_opcodes(2);
58    println!("{:?}", grouped_opcodes);
59    let ratio = matcher.ratio();
60    println!("{:?}", ratio);
61    matcher.set_seqs("aaaaa", "aaaab");
62    println!("{:?}", matcher.ratio());
63}
Source

pub fn get_grouped_opcodes(&mut self, n: usize) -> Vec<Vec<Opcode>>

Examples found in repository?
examples/example.rs (line 57)
6fn main() {
7    // unified_diff
8    let first_text = "one two three four".split(" ").collect::<Vec<&str>>();
9    let second_text = "zero one tree four".split(" ").collect::<Vec<&str>>();
10    let diff = difflib::unified_diff(
11        &first_text,
12        &second_text,
13        "Original",
14        "Current",
15        "2005-01-26 23:30:50",
16        "2010-04-02 10:20:52",
17        3,
18    );
19    for line in &diff {
20        println!("{:?}", line);
21    }
22
23    //context_diff
24    let diff = difflib::context_diff(
25        &first_text,
26        &second_text,
27        "Original",
28        "Current",
29        "2005-01-26 23:30:50",
30        "2010-04-02 10:20:52",
31        3,
32    );
33    for line in &diff {
34        println!("{:?}", line);
35    }
36
37    //get_close_matches
38    let words = vec!["ape", "apple", "peach", "puppy"];
39    let result = difflib::get_close_matches("appel", words, 3, 0.6);
40    println!("{:?}", result);
41
42    //Differ examples
43    let differ = Differ::new();
44    let diff = differ.compare(&first_text, &second_text);
45    for line in &diff {
46        println!("{:?}", line);
47    }
48
49    //SequenceMatcher examples
50    let mut matcher = SequenceMatcher::new("one two three four", "zero one tree four");
51    let m = matcher.find_longest_match(0, 18, 0, 18);
52    println!("{:?}", m);
53    let all_matches = matcher.get_matching_blocks();
54    println!("{:?}", all_matches);
55    let opcode = matcher.get_opcodes();
56    println!("{:?}", opcode);
57    let grouped_opcodes = matcher.get_grouped_opcodes(2);
58    println!("{:?}", grouped_opcodes);
59    let ratio = matcher.ratio();
60    println!("{:?}", ratio);
61    matcher.set_seqs("aaaaa", "aaaab");
62    println!("{:?}", matcher.ratio());
63}
Source

pub fn ratio(&mut self) -> f32

Examples found in repository?
examples/example.rs (line 59)
6fn main() {
7    // unified_diff
8    let first_text = "one two three four".split(" ").collect::<Vec<&str>>();
9    let second_text = "zero one tree four".split(" ").collect::<Vec<&str>>();
10    let diff = difflib::unified_diff(
11        &first_text,
12        &second_text,
13        "Original",
14        "Current",
15        "2005-01-26 23:30:50",
16        "2010-04-02 10:20:52",
17        3,
18    );
19    for line in &diff {
20        println!("{:?}", line);
21    }
22
23    //context_diff
24    let diff = difflib::context_diff(
25        &first_text,
26        &second_text,
27        "Original",
28        "Current",
29        "2005-01-26 23:30:50",
30        "2010-04-02 10:20:52",
31        3,
32    );
33    for line in &diff {
34        println!("{:?}", line);
35    }
36
37    //get_close_matches
38    let words = vec!["ape", "apple", "peach", "puppy"];
39    let result = difflib::get_close_matches("appel", words, 3, 0.6);
40    println!("{:?}", result);
41
42    //Differ examples
43    let differ = Differ::new();
44    let diff = differ.compare(&first_text, &second_text);
45    for line in &diff {
46        println!("{:?}", line);
47    }
48
49    //SequenceMatcher examples
50    let mut matcher = SequenceMatcher::new("one two three four", "zero one tree four");
51    let m = matcher.find_longest_match(0, 18, 0, 18);
52    println!("{:?}", m);
53    let all_matches = matcher.get_matching_blocks();
54    println!("{:?}", all_matches);
55    let opcode = matcher.get_opcodes();
56    println!("{:?}", opcode);
57    let grouped_opcodes = matcher.get_grouped_opcodes(2);
58    println!("{:?}", grouped_opcodes);
59    let ratio = matcher.ratio();
60    println!("{:?}", ratio);
61    matcher.set_seqs("aaaaa", "aaaab");
62    println!("{:?}", matcher.ratio());
63}

Auto Trait Implementations§

§

impl<'a, T> Freeze for SequenceMatcher<'a, T>

§

impl<'a, T> RefUnwindSafe for SequenceMatcher<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for SequenceMatcher<'a, T>
where T: Sync,

§

impl<'a, T> Sync for SequenceMatcher<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for SequenceMatcher<'a, T>

§

impl<'a, T> UnwindSafe for SequenceMatcher<'a, T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.