Skip to content

Commit 88a557c

Browse files
committed
Autofix of clippy::use_self
1 parent eb6a193 commit 88a557c

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/lib.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl QueueFile {
203203
if force_legacy {
204204
buf.put_u32(capacity as u32);
205205
} else {
206-
buf.put_u32(QueueFile::VERSIONED_HEADER);
206+
buf.put_u32(Self::VERSIONED_HEADER);
207207
buf.put_u64(capacity);
208208
}
209209

@@ -225,7 +225,7 @@ impl QueueFile {
225225
/// # let path = auto_delete_path::AutoDeletePath::temp();
226226
/// let qf = QueueFile::with_capacity(path, 120).expect("failed to open queue");
227227
/// ```
228-
pub fn with_capacity<P: AsRef<Path>>(path: P, capacity: u64) -> Result<QueueFile> {
228+
pub fn with_capacity<P: AsRef<Path>>(path: P, capacity: u64) -> Result<Self> {
229229
Self::open_internal(path, true, false, capacity)
230230
}
231231

@@ -238,8 +238,8 @@ impl QueueFile {
238238
/// # let path = auto_delete_path::AutoDeletePath::temp();
239239
/// let qf = QueueFile::open(path).expect("failed to open queue");
240240
/// ```
241-
pub fn open<P: AsRef<Path>>(path: P) -> Result<QueueFile> {
242-
Self::with_capacity(path, QueueFile::INITIAL_LENGTH)
241+
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self> {
242+
Self::with_capacity(path, Self::INITIAL_LENGTH)
243243
}
244244

245245
/// Open or create [QueueFile] at `path` forcing legacy format.
@@ -251,15 +251,15 @@ impl QueueFile {
251251
/// # let path = auto_delete_path::AutoDeletePath::temp();
252252
/// let qf = QueueFile::open_legacy(path).expect("failed to open queue");
253253
/// ```
254-
pub fn open_legacy<P: AsRef<Path>>(path: P) -> Result<QueueFile> {
255-
Self::open_internal(path, true, true, QueueFile::INITIAL_LENGTH)
254+
pub fn open_legacy<P: AsRef<Path>>(path: P) -> Result<Self> {
255+
Self::open_internal(path, true, true, Self::INITIAL_LENGTH)
256256
}
257257

258258
fn open_internal<P: AsRef<Path>>(
259259
path: P, overwrite_on_remove: bool, force_legacy: bool, capacity: u64,
260-
) -> Result<QueueFile> {
260+
) -> Result<Self> {
261261
if !path.as_ref().exists() {
262-
QueueFile::init(path.as_ref(), force_legacy, capacity)?;
262+
Self::init(path.as_ref(), force_legacy, capacity)?;
263263
}
264264

265265
let mut file = OpenOptions::new().read(true).write(true).open(path)?;
@@ -327,7 +327,7 @@ impl QueueFile {
327327
msg: format!("position of the last element ({last_pos}) is beyond the file")
328328
});
329329

330-
let mut queue_file = QueueFile {
330+
let mut queue_file = Self {
331331
inner: QueueFileInner {
332332
file: ManuallyDrop::new(file),
333333
file_len,
@@ -668,15 +668,15 @@ impl QueueFile {
668668
if self.overwrite_on_remove {
669669
self.inner.seek(self.header_len)?;
670670
let first_block = self.capacity.min(Self::BLOCK_LENGTH) - self.header_len;
671-
self.inner.write(&QueueFile::ZEROES[..first_block as usize])?;
671+
self.inner.write(&Self::ZEROES[..first_block as usize])?;
672672

673673
if let Some(left) = self.capacity.checked_sub(Self::BLOCK_LENGTH) {
674674
for _ in 0..left / Self::BLOCK_LENGTH {
675-
self.inner.write(&QueueFile::ZEROES)?;
675+
self.inner.write(&Self::ZEROES)?;
676676
}
677677
let tail = left % Self::BLOCK_LENGTH;
678678
if tail != 0 {
679-
self.inner.write(&QueueFile::ZEROES[..tail as usize])?;
679+
self.inner.write(&Self::ZEROES[..tail as usize])?;
680680
}
681681
}
682682
}
@@ -784,7 +784,7 @@ impl QueueFile {
784784
assert!(first_pos <= i64::max_value() as u64);
785785
assert!(last_pos <= i64::max_value() as u64);
786786

787-
header_buf.put_u32(QueueFile::VERSIONED_HEADER);
787+
header_buf.put_u32(Self::VERSIONED_HEADER);
788788
header_buf.put_u64(file_len);
789789
header_buf.put_i32(elem_cnt as i32);
790790
header_buf.put_u64(first_pos);
@@ -845,9 +845,9 @@ impl QueueFile {
845845
let mut len = n;
846846

847847
self.write_buf.clear();
848-
self.write_buf.extend(QueueFile::ZEROES);
848+
self.write_buf.extend(Self::ZEROES);
849849
while len > 0 {
850-
let chunk_len = min(len, QueueFile::ZEROES.len());
850+
let chunk_len = min(len, Self::ZEROES.len());
851851
self.write_buf.truncate(chunk_len);
852852

853853
self.ring_write_buf(pos)?;
@@ -1128,7 +1128,7 @@ struct Element {
11281128
}
11291129

11301130
impl Element {
1131-
const EMPTY: Element = Element { pos: 0, len: 0 };
1131+
const EMPTY: Self = Self { pos: 0, len: 0 };
11321132
const HEADER_LENGTH: usize = 4;
11331133

11341134
fn new(pos: u64, len: usize) -> Self {
@@ -1143,7 +1143,7 @@ impl Element {
11431143
i32::max_value()
11441144
);
11451145

1146-
Element { pos, len }
1146+
Self { pos, len }
11471147
}
11481148
}
11491149

tests/test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ enum Action {
5555

5656
impl quickcheck::Arbitrary for Action {
5757
fn arbitrary(mut g: &mut quickcheck::Gen) -> Self {
58-
let kind = u32::arbitrary(&mut g);
58+
let kind = u32::arbitrary(g);
5959

6060
match kind % 3 {
6161
0 => Self::Add(Vec::arbitrary(g)),
6262
1 => Self::Remove(usize::arbitrary(g)),
63-
2 => Self::Read { skip: usize::arbitrary(&mut g), take: usize::arbitrary(&mut g) },
63+
2 => Self::Read { skip: usize::arbitrary(g), take: usize::arbitrary(g) },
6464
_ => unreachable!(),
6565
}
6666
}
@@ -296,13 +296,13 @@ fn iter_nth() {
296296
let c = vec![4, 5, 6];
297297
qf.add_n(vec![a.clone(), b.clone(), c.clone()]).unwrap();
298298

299-
assert_eq!(qf.iter().nth(0), Some(a.into_boxed_slice()));
299+
assert_eq!(qf.iter().next(), Some(a.into_boxed_slice()));
300300
assert_eq!(qf.iter().nth(1), Some(b.clone().into_boxed_slice()));
301301
assert_eq!(qf.iter().nth(2), Some(c.clone().into_boxed_slice()));
302302
assert_eq!(qf.iter().skip(0).nth(1), Some(b.clone().into_boxed_slice()));
303303
assert_eq!(qf.iter().skip(0).nth(2), Some(c.clone().into_boxed_slice()));
304-
assert_eq!(qf.iter().skip(1).nth(0), Some(b.clone().into_boxed_slice()));
305-
assert_eq!(qf.iter().skip(1).nth(1), Some(c.clone().into_boxed_slice()));
304+
assert_eq!(qf.iter().skip(1).next(), Some(b.into_boxed_slice()));
305+
assert_eq!(qf.iter().skip(1).nth(1), Some(c.into_boxed_slice()));
306306
assert_eq!(qf.iter().nth(3), None);
307307
assert_eq!(qf.iter().nth(123), None);
308308
}

0 commit comments

Comments
 (0)