Skip to content

Commit f516d15

Browse files
committed
refactor: move iterator to its own module
1 parent 82bdd57 commit f516d15

2 files changed

Lines changed: 67 additions & 61 deletions

File tree

src/hardlink/link_path_list.rs

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
mod iter;
12
mod reflection;
23

4+
pub use iter::Iter;
35
pub use reflection::Reflection;
46

57
pub use Reflection as LinkPathListReflection;
68

7-
use pipe_trait::Pipe;
8-
use std::{iter::FusedIterator, path::PathBuf, slice};
9+
use std::path::PathBuf;
910

1011
/// List of different hardlinks to the same file.
1112
///
@@ -38,67 +39,8 @@ impl LinkPathList {
3839
self.0.is_empty()
3940
}
4041

41-
/// Iterate over the paths inside the list.
42-
pub fn iter(&self) -> Iter {
43-
self.0.iter().pipe(Iter)
44-
}
45-
4642
/// Create reflection.
4743
pub fn into_reflection(self) -> Reflection {
4844
self.into()
4945
}
5046
}
51-
52-
/// [Iterator] over the paths inside a [`LinkPathList`].
53-
#[derive(Debug, Clone)]
54-
pub struct Iter<'a>(slice::Iter<'a, PathBuf>);
55-
56-
impl<'a> Iterator for Iter<'a> {
57-
type Item = &'a PathBuf;
58-
59-
#[inline]
60-
fn next(&mut self) -> Option<Self::Item> {
61-
self.0.next()
62-
}
63-
64-
#[inline]
65-
fn size_hint(&self) -> (usize, Option<usize>) {
66-
self.0.size_hint()
67-
}
68-
69-
#[inline]
70-
fn count(self) -> usize {
71-
self.0.count()
72-
}
73-
74-
#[inline]
75-
fn nth(&mut self, n: usize) -> Option<Self::Item> {
76-
self.0.nth(n)
77-
}
78-
79-
#[inline]
80-
fn last(self) -> Option<Self::Item> {
81-
self.0.last()
82-
}
83-
}
84-
85-
impl<'a> DoubleEndedIterator for Iter<'a> {
86-
#[inline]
87-
fn next_back(&mut self) -> Option<Self::Item> {
88-
self.0.next_back()
89-
}
90-
91-
#[inline]
92-
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
93-
self.0.nth_back(n)
94-
}
95-
}
96-
97-
impl<'a> ExactSizeIterator for Iter<'a> {
98-
#[inline]
99-
fn len(&self) -> usize {
100-
self.0.len()
101-
}
102-
}
103-
104-
impl FusedIterator for Iter<'_> {}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use super::LinkPathList;
2+
use pipe_trait::Pipe;
3+
use std::{iter::FusedIterator, path::PathBuf, slice};
4+
5+
/// [Iterator] over the paths inside a [`LinkPathList`].
6+
#[derive(Debug, Clone)]
7+
pub struct Iter<'a>(slice::Iter<'a, PathBuf>);
8+
9+
impl LinkPathList {
10+
/// Iterate over the paths inside the list.
11+
pub fn iter(&self) -> Iter {
12+
self.0.iter().pipe(Iter)
13+
}
14+
}
15+
16+
impl<'a> Iterator for Iter<'a> {
17+
type Item = &'a PathBuf;
18+
19+
#[inline]
20+
fn next(&mut self) -> Option<Self::Item> {
21+
self.0.next()
22+
}
23+
24+
#[inline]
25+
fn size_hint(&self) -> (usize, Option<usize>) {
26+
self.0.size_hint()
27+
}
28+
29+
#[inline]
30+
fn count(self) -> usize {
31+
self.0.count()
32+
}
33+
34+
#[inline]
35+
fn nth(&mut self, n: usize) -> Option<Self::Item> {
36+
self.0.nth(n)
37+
}
38+
39+
#[inline]
40+
fn last(self) -> Option<Self::Item> {
41+
self.0.last()
42+
}
43+
}
44+
45+
impl<'a> DoubleEndedIterator for Iter<'a> {
46+
#[inline]
47+
fn next_back(&mut self) -> Option<Self::Item> {
48+
self.0.next_back()
49+
}
50+
51+
#[inline]
52+
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
53+
self.0.nth_back(n)
54+
}
55+
}
56+
57+
impl<'a> ExactSizeIterator for Iter<'a> {
58+
#[inline]
59+
fn len(&self) -> usize {
60+
self.0.len()
61+
}
62+
}
63+
64+
impl FusedIterator for Iter<'_> {}

0 commit comments

Comments
 (0)