ratatui_toolkit/widgets/code_diff/foundation/diff_hunk/methods/removed_count.rs
1use crate::widgets::code_diff::diff_hunk::DiffHunk;
2
3impl DiffHunk {
4 /// Returns the number of removed lines in this hunk.
5 ///
6 /// # Returns
7 ///
8 /// The count of lines with `DiffLineKind::Removed`
9 ///
10 /// # Example
11 ///
12 /// ```rust
13 /// use ratatui_toolkit::code_diff::{DiffHunk, DiffLine};
14 ///
15 /// let mut hunk = DiffHunk::new(1, 3, 1, 2);
16 /// hunk.add_line(DiffLine::removed("old line 1", 1));
17 /// hunk.add_line(DiffLine::removed("old line 2", 2));
18 /// assert_eq!(hunk.removed_count(), 2);
19 /// ```
20 pub fn removed_count(&self) -> usize {
21 self.lines.iter().filter(|l| l.is_removed()).count()
22 }
23}