Skip to content
Dima Kudosh edited this page Mar 1, 2016 · 10 revisions

Difflib

Port of Python's difflib library to Rust. It's provide all necessary tools for comparing word sequences.

Installation

Simply add difflib to your dependencies block in Cargo.toml

[dependencies]
difflib = "0.1"

Usage

Sequence trait implements for str and Vec of str, so all parameterized functions(structs) accepts only this types.

  • fn context_diff<T: Sequence>(first_sequence: &T, second_sequence: &T, from_file: &str, to_file: &str, from_file_date: &str, to_file_date: &str, n: usize) -> Vec<String>

Compare first_sequence and second_sequence (vector of strings) and return vector of strings delta in context diff format. Context diffs are a compact way of showing just the lines that have changed plus a few lines of context. The changes are shown in a before/after style. The number of context lines is set by n which defaults to three. Context diff format has a header for filenames and modification times. Any or all of these may be specified using strings for from_file, to_file, from_file_date, and to_file_date.

  • fn unified_diff<T: Sequence>(first_sequence: &T, second_sequence: &T, from_file: &str, to_file: &str, from_file_date: &str, to_file_date: &str, n: usize) -> Vec<String>

Compare first_sequence and second_sequence (vector of strings) and return vector of strings delta in unified diff format. Unified diffs are a compact way of showing just the lines that have changed plus a few lines of context. The changes are shown in a before/after style. The number of context lines is set by n which defaults to three. Unified diff format has a header for filenames and modification times. Any or all of these may be specified using strings for from_file, to_file, from_file_date, and to_file_date.

  • fn get_close_matches<'a>(word: &str, possibilities: Vec<&'a str>, n: usize, cutoff: f32) -> Vec<&'a str> Return a list of the n best matches.

Clone this wiki locally