Skip to content

Commit 4e568a5

Browse files
committed
diff: #[derive(Default)]
1 parent 8f878a9 commit 4e568a5

File tree

2 files changed

+6
-40
lines changed

2 files changed

+6
-40
lines changed

text/diff_util/file_diff.rs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'a> FileDiff<'a> {
4444
Self {
4545
file1,
4646
file2,
47-
hunks: Hunks::new(),
47+
hunks: Default::default(),
4848
format_options,
4949
are_different: false,
5050
}
@@ -331,7 +331,7 @@ impl<'a> FileDiff<'a> {
331331
Self::get_header(self.file2, self.format_options.label2())
332332
);
333333

334-
let mut diff_disp = ContextDiffDisplay::new();
334+
let mut diff_disp = ContextDiffDisplay::default();
335335

336336
for hunk in self.hunks.hunks() {
337337
// move cursor to the start of context for first hunk
@@ -458,7 +458,7 @@ impl<'a> FileDiff<'a> {
458458
Self::get_header(self.file2, self.format_options.label2())
459459
);
460460

461-
let mut diff_disp = UnifiedDiffDisplay::new();
461+
let mut diff_disp = UnifiedDiffDisplay::default();
462462

463463
for hunk in self.hunks.hunks() {
464464
// move cursor to the start of context for first hunk
@@ -526,6 +526,7 @@ impl<'a> FileDiff<'a> {
526526
}
527527
}
528528

529+
#[derive(Default)]
529530
pub struct UnifiedDiffDisplay {
530531
curr_pos1: usize,
531532
curr_pos2: usize,
@@ -540,18 +541,6 @@ pub struct UnifiedDiffDisplay {
540541
}
541542

542543
impl UnifiedDiffDisplay {
543-
pub fn new() -> Self {
544-
Self {
545-
curr_pos1: 0,
546-
curr_pos2: 0,
547-
context_start1: 0,
548-
context_start2: 0,
549-
hunk1_len: 0,
550-
hunk2_len: 0,
551-
hunk_lines: String::new(),
552-
}
553-
}
554-
555544
pub fn write_line(
556545
&mut self,
557546
file: &FileData,
@@ -607,6 +596,7 @@ impl UnifiedDiffDisplay {
607596
}
608597
}
609598

599+
#[derive(Default)]
610600
pub struct ContextDiffDisplay {
611601
curr_pos1: usize,
612602
curr_pos2: usize,
@@ -621,18 +611,6 @@ pub struct ContextDiffDisplay {
621611
}
622612

623613
impl ContextDiffDisplay {
624-
pub fn new() -> Self {
625-
Self {
626-
curr_pos1: 0,
627-
curr_pos2: 0,
628-
context_start1: 0,
629-
context_start2: 0,
630-
hunk1_len: 0,
631-
hunk2_len: 0,
632-
hunk_lines: [String::new(), String::new()],
633-
}
634-
}
635-
636614
pub fn set_context_start(&mut self) {
637615
self.context_start1 = self.curr_pos1 + 1;
638616
self.context_start2 = self.curr_pos2 + 1;

text/diff_util/hunks.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ impl Default for Hunk {
3333
}
3434

3535
impl Hunk {
36-
pub fn new() -> Self {
37-
Self::default()
38-
}
39-
4036
pub fn f1_range(&self, is_ed: bool) -> String {
4137
if self.ln1_start == self.ln1_end {
4238
format!("{}", self.ln1_start)
@@ -193,20 +189,12 @@ impl Hunk {
193189
}
194190
}
195191

192+
#[derive(Default)]
196193
pub struct Hunks {
197194
hunks: Vec<Hunk>,
198195
}
199196

200197
impl Hunks {
201-
pub fn new() -> Self {
202-
Self {
203-
hunks: {
204-
Hunk::new();
205-
vec![] as Vec<Hunk>
206-
},
207-
}
208-
}
209-
210198
pub fn hunks(&self) -> &Vec<Hunk> {
211199
&self.hunks
212200
}

0 commit comments

Comments
 (0)