dtolnay / dissimilar

Diff library with semantic cleanup, based on Google's diff-match-patch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Convenience method to access string

k12ish opened this issue · comments

commented

Sometimes, I process chunks indifferently to each other:

let diff_size = chunk_vec
    .iter()
    .map(|s| match s {
        Chunk::Equal(s) => s.len(),
        Chunk::Delete(s) => s.len(),
        Chunk::Insert(s) => s.len(),
    })
    .sum();

It would be nice to have a method that cuts down on the boilerplate:

let diff_size = chunk_vec.iter().map(|s| s.inner().len()).sum();

Forgive me if this is impossible, I am quite new to Rust.

commented

Found a solution!

let (Chunk::Equal(s) | Chunk::Delete(s) | Chunk::Insert(s)) = chunk;