Skip to content
Dima Kudosh edited this page Feb 29, 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, lineterm: &str) -> 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. For inputs that do not have trailing newlines, set the lineterm argument to "" so that the output will be uniformly newline free.

Clone this wiki locally