Skip to content

Commit 21db697

Browse files
adamnemecekfolkertdev
authored andcommitted
ran cargo clippy --fix -- -A clippy::all -W clippy::use_self
1 parent 71d5b03 commit 21db697

File tree

5 files changed

+40
-40
lines changed

5 files changed

+40
-40
lines changed

src/bufread.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pub struct BzDecoder<R> {
2929
impl<R: BufRead> BzEncoder<R> {
3030
/// Creates a new encoder which will read uncompressed data from the given
3131
/// stream and emit the compressed stream.
32-
pub fn new(r: R, level: Compression) -> BzEncoder<R> {
33-
BzEncoder {
32+
pub fn new(r: R, level: Compression) -> Self {
33+
Self {
3434
obj: r,
3535
data: Compress::new(level, 30),
3636
done: false,
@@ -127,16 +127,16 @@ impl<W: Write> Write for BzEncoder<W> {
127127
impl<R: BufRead> BzDecoder<R> {
128128
/// Creates a new decoder which will decompress data read from the given
129129
/// stream.
130-
pub fn new(r: R) -> BzDecoder<R> {
131-
BzDecoder {
130+
pub fn new(r: R) -> Self {
131+
Self {
132132
obj: r,
133133
data: Decompress::new(false),
134134
done: false,
135135
multi: false,
136136
}
137137
}
138138

139-
fn multi(mut self, flag: bool) -> BzDecoder<R> {
139+
fn multi(mut self, flag: bool) -> Self {
140140
self.multi = flag;
141141
self
142142
}
@@ -240,8 +240,8 @@ pub struct MultiBzDecoder<R>(BzDecoder<R>);
240240
impl<R: BufRead> MultiBzDecoder<R> {
241241
/// Creates a new decoder from the given reader. If the bzip2 stream contains multiple members
242242
/// all will be decoded.
243-
pub fn new(r: R) -> MultiBzDecoder<R> {
244-
MultiBzDecoder(BzDecoder::new(r).multi(true))
243+
pub fn new(r: R) -> Self {
244+
Self(BzDecoder::new(r).multi(true))
245245
}
246246
}
247247

src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,35 +88,35 @@ impl Compression {
8888
/// A level outside of the `1..=9` range will throw a panic. Use [`Self::try_new`] to
8989
/// gracefully handle invalid levels (e.g. from user input).
9090
#[track_caller]
91-
pub const fn new(level: u32) -> Compression {
91+
pub const fn new(level: u32) -> Self {
9292
match Self::try_new(level) {
9393
Some(v) => v,
9494
None => panic!("expected a compression level in the range 1..=9"),
9595
}
9696
}
9797

9898
/// Create a new compression spec with a specific numeric level in the range `1..=9`.
99-
pub const fn try_new(level: u32) -> Option<Compression> {
99+
pub const fn try_new(level: u32) -> Option<Self> {
100100
match level {
101-
1..=9 => Some(Compression(level)),
101+
1..=9 => Some(Self(level)),
102102
_ => None,
103103
}
104104
}
105105

106106
/// Do not compress.
107107
#[deprecated(since = "0.5.1", note = "libbz2 does not support compression level 0")]
108-
pub fn none() -> Compression {
109-
Compression(0)
108+
pub fn none() -> Self {
109+
Self(0)
110110
}
111111

112112
/// Optimize for the best speed of encoding.
113-
pub const fn fast() -> Compression {
114-
Compression(1)
113+
pub const fn fast() -> Self {
114+
Self(1)
115115
}
116116

117117
/// Optimize for smallest output size.
118-
pub const fn best() -> Compression {
119-
Compression(9)
118+
pub const fn best() -> Self {
119+
Self(9)
120120
}
121121

122122
/// Return the compression level as an integer.
@@ -127,8 +127,8 @@ impl Compression {
127127

128128
impl Default for Compression {
129129
/// Choose the default compression, a balance between speed and size.
130-
fn default() -> Compression {
131-
Compression(6)
130+
fn default() -> Self {
131+
Self(6)
132132
}
133133
}
134134

src/mem.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ impl Compress {
117117
///
118118
/// Allowable values range from 0 to 250 inclusive. 0 is a special case,
119119
/// equivalent to using the default value of 30.
120-
pub fn new(lvl: Compression, work_factor: u32) -> Compress {
120+
pub fn new(lvl: Compression, work_factor: u32) -> Self {
121121
unsafe {
122122
let mut raw = Box::new(mem::zeroed());
123123
assert_eq!(
124124
ffi::BZ2_bzCompressInit(&mut *raw, lvl.level() as c_int, 0, work_factor as c_int),
125125
0
126126
);
127-
Compress {
127+
Self {
128128
inner: Stream {
129129
raw,
130130
_marker: marker::PhantomData,
@@ -163,7 +163,7 @@ impl Compress {
163163
ffi::BZ_FINISH_OK => Ok(Status::FinishOk),
164164
ffi::BZ_STREAM_END => Ok(Status::StreamEnd),
165165
ffi::BZ_SEQUENCE_ERROR => Err(Error::Sequence),
166-
c => panic!("unknown return status: {}", c),
166+
c => panic!("unknown return status: {c}"),
167167
}
168168
}
169169
}
@@ -213,11 +213,11 @@ impl Decompress {
213213
/// decompression algorithm which uses less memory but at the cost of
214214
/// decompressing more slowly (roughly speaking, half the speed, but the
215215
/// maximum memory requirement drops to around 2300k).
216-
pub fn new(small: bool) -> Decompress {
216+
pub fn new(small: bool) -> Self {
217217
unsafe {
218218
let mut raw = Box::new(mem::zeroed());
219219
assert_eq!(ffi::BZ2_bzDecompressInit(&mut *raw, 0, small as c_int), 0);
220-
Decompress {
220+
Self {
221221
inner: Stream {
222222
raw,
223223
_marker: marker::PhantomData,
@@ -241,7 +241,7 @@ impl Decompress {
241241
ffi::BZ_DATA_ERROR => Err(Error::Data),
242242
ffi::BZ_DATA_ERROR_MAGIC => Err(Error::DataMagic),
243243
ffi::BZ_SEQUENCE_ERROR => Err(Error::Sequence),
244-
c => panic!("wut: {}", c),
244+
c => panic!("wut: {c}"),
245245
}
246246
}
247247
}
@@ -294,18 +294,18 @@ impl error::Error for Error {}
294294
impl fmt::Display for Error {
295295
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
296296
let description = match self {
297-
Error::Sequence => "bzip2: sequence of operations invalid",
298-
Error::Data => "bzip2: invalid data",
299-
Error::DataMagic => "bzip2: bz2 header missing",
300-
Error::Param => "bzip2: invalid parameters",
297+
Self::Sequence => "bzip2: sequence of operations invalid",
298+
Self::Data => "bzip2: invalid data",
299+
Self::DataMagic => "bzip2: bz2 header missing",
300+
Self::Param => "bzip2: invalid parameters",
301301
};
302302
f.write_str(description)
303303
}
304304
}
305305

306306
impl From<Error> for std::io::Error {
307-
fn from(data: Error) -> std::io::Error {
308-
std::io::Error::other(data)
307+
fn from(data: Error) -> Self {
308+
Self::other(data)
309309
}
310310
}
311311

src/read.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pub struct BzDecoder<R> {
2121
impl<R: Read> BzEncoder<R> {
2222
/// Create a new compression stream which will compress at the given level
2323
/// to read compress output to the give output stream.
24-
pub fn new(r: R, level: Compression) -> BzEncoder<R> {
25-
BzEncoder {
24+
pub fn new(r: R, level: Compression) -> Self {
25+
Self {
2626
inner: bufread::BzEncoder::new(BufReader::new(r), level),
2727
}
2828
}
@@ -84,8 +84,8 @@ impl<W: Write + Read> Write for BzEncoder<W> {
8484
impl<R: Read> BzDecoder<R> {
8585
/// Create a new decompression stream, which will read compressed
8686
/// data from the given input stream and decompress it.
87-
pub fn new(r: R) -> BzDecoder<R> {
88-
BzDecoder {
87+
pub fn new(r: R) -> Self {
88+
Self {
8989
inner: bufread::BzDecoder::new(BufReader::new(r)),
9090
}
9191
}
@@ -153,8 +153,8 @@ impl<R: Read> MultiBzDecoder<R> {
153153
/// Creates a new decoder from the given reader, immediately parsing the
154154
/// (first) gzip header. If the gzip stream contains multiple members all will
155155
/// be decoded.
156-
pub fn new(r: R) -> MultiBzDecoder<R> {
157-
MultiBzDecoder {
156+
pub fn new(r: R) -> Self {
157+
Self {
158158
inner: bufread::MultiBzDecoder::new(BufReader::new(r)),
159159
}
160160
}

src/write.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ pub struct BzDecoder<W: Write> {
2828
impl<W: Write> BzEncoder<W> {
2929
/// Create a new compression stream which will compress at the given level
3030
/// to write compress output to the give output stream.
31-
pub fn new(obj: W, level: Compression) -> BzEncoder<W> {
32-
BzEncoder {
31+
pub fn new(obj: W, level: Compression) -> Self {
32+
Self {
3333
data: Compress::new(level, 30),
3434
obj: Some(obj),
3535
buf: Vec::with_capacity(32 * 1024),
@@ -162,8 +162,8 @@ impl<W: Write> Write for BzEncoder<W> {
162162
impl<W: Write> BzDecoder<W> {
163163
/// Create a new decoding stream which will decompress all data written
164164
/// to it into `obj`.
165-
pub fn new(obj: W) -> BzDecoder<W> {
166-
BzDecoder {
165+
pub fn new(obj: W) -> Self {
166+
Self {
167167
data: Decompress::new(false),
168168
obj: Some(obj),
169169
buf: Vec::with_capacity(32 * 1024),

0 commit comments

Comments
 (0)