Skip to content

Commit 1567c81

Browse files
authored
Merge pull request #457 from CosminPerRam/feat/remove_explicit_default
feat: remove explicit default impls
2 parents 02e4544 + c3ec0f8 commit 1567c81

File tree

2 files changed

+7
-33
lines changed

2 files changed

+7
-33
lines changed

src/crc.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crc32fast::Hasher;
88
/// The CRC calculated by a [`CrcReader`].
99
///
1010
/// [`CrcReader`]: struct.CrcReader.html
11-
#[derive(Debug)]
11+
#[derive(Debug, Default)]
1212
pub struct Crc {
1313
amt: u32,
1414
hasher: Hasher,
@@ -23,19 +23,10 @@ pub struct CrcReader<R> {
2323
crc: Crc,
2424
}
2525

26-
impl Default for Crc {
27-
fn default() -> Self {
28-
Self::new()
29-
}
30-
}
31-
3226
impl Crc {
3327
/// Create a new CRC.
34-
pub fn new() -> Crc {
35-
Crc {
36-
amt: 0,
37-
hasher: Hasher::new(),
38-
}
28+
pub fn new() -> Self {
29+
Self::default()
3930
}
4031

4132
/// Returns the current crc32 checksum.

src/gz/mod.rs

+4-21
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,18 @@ impl GzHeader {
8787
}
8888
}
8989

90-
#[derive(Debug)]
90+
#[derive(Debug, Default)]
9191
pub enum GzHeaderState {
9292
Start(u8, [u8; 10]),
9393
Xlen(Option<Box<Crc>>, u8, [u8; 2]),
9494
Extra(Option<Box<Crc>>, u16),
9595
Filename(Option<Box<Crc>>),
9696
Comment(Option<Box<Crc>>),
9797
Crc(Option<Box<Crc>>, u8, [u8; 2]),
98+
#[default]
9899
Complete,
99100
}
100101

101-
impl Default for GzHeaderState {
102-
fn default() -> Self {
103-
Self::Complete
104-
}
105-
}
106-
107102
#[derive(Debug, Default)]
108103
pub struct GzHeaderParser {
109104
state: GzHeaderState,
@@ -317,7 +312,7 @@ fn corrupt() -> Error {
317312
/// # Ok(())
318313
/// # }
319314
/// ```
320-
#[derive(Debug)]
315+
#[derive(Debug, Default)]
321316
pub struct GzBuilder {
322317
extra: Option<Vec<u8>>,
323318
filename: Option<CString>,
@@ -326,22 +321,10 @@ pub struct GzBuilder {
326321
mtime: u32,
327322
}
328323

329-
impl Default for GzBuilder {
330-
fn default() -> Self {
331-
Self::new()
332-
}
333-
}
334-
335324
impl GzBuilder {
336325
/// Create a new blank builder with no header by default.
337326
pub fn new() -> GzBuilder {
338-
GzBuilder {
339-
extra: None,
340-
filename: None,
341-
comment: None,
342-
operating_system: None,
343-
mtime: 0,
344-
}
327+
Self::default()
345328
}
346329

347330
/// Configure the `mtime` field in the gzip header.

0 commit comments

Comments
 (0)