Convenience method to access string
k12ish opened this issue · comments
Krish 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.
Krish commented
Found a solution!
let (Chunk::Equal(s) | Chunk::Delete(s) | Chunk::Insert(s)) = chunk;