1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use git_object::bstr::BStr;
/// The crate powering file diffs.
pub use imara_diff as imara;
pub use imara_diff::Algorithm;

/// Create a diff yielding the changes to turn `old` into `new` with `algorithm`. `new_input` obtains the `old` and `new`
/// byte buffers and produces an interner, which is then passed to `new_sink` for creating a processor over the changes.
///
/// See [the `imara-diff` crate documentation][imara] for information on how to implement a [`Sink`][imara::Sink].
pub fn with<'a, FnI, FnS, S>(
    old: &'a BStr,
    new: &'a BStr,
    algorithm: Algorithm,
    new_input: FnI,
    new_sink: FnS,
) -> (imara::intern::InternedInput<&'a [u8]>, S::Out)
where
    FnI: FnOnce(&'a [u8], &'a [u8]) -> imara::intern::InternedInput<&'a [u8]>,
    FnS: FnOnce(&imara::intern::InternedInput<&'a [u8]>) -> S,
    S: imara_diff::Sink,
{
    let input = new_input(old.as_ref(), new.as_ref());
    let sink = new_sink(&input);
    let out = imara::diff(algorithm, &input, sink);
    (input, out)
}