File tree Expand file tree Collapse file tree 4 files changed +494
-499
lines changed Expand file tree Collapse file tree 4 files changed +494
-499
lines changed Original file line number Diff line number Diff line change
1
+ use std:: iter:: FusedIterator ;
2
+
3
+ use crate :: path:: Path ;
4
+
5
+ /// An iterator over [`Path`] and its ancestors.
6
+ ///
7
+ /// This `struct` is created by the [`ancestors`] method on [`Path`].
8
+ /// See its documentation for more.
9
+ ///
10
+ /// # Examples
11
+ ///
12
+ /// ```
13
+ /// use async_std::path::Path;
14
+ ///
15
+ /// let path = Path::new("/foo/bar");
16
+ ///
17
+ /// for ancestor in path.ancestors() {
18
+ /// println!("{}", ancestor.display());
19
+ /// }
20
+ /// ```
21
+ ///
22
+ /// [`ancestors`]: struct.Path.html#method.ancestors
23
+ /// [`Path`]: struct.Path.html
24
+ #[ derive( Copy , Clone , Debug ) ]
25
+ pub struct Ancestors < ' a > {
26
+ pub ( crate ) next : Option < & ' a Path > ,
27
+ }
28
+
29
+ impl < ' a > Iterator for Ancestors < ' a > {
30
+ type Item = & ' a Path ;
31
+
32
+ fn next ( & mut self ) -> Option < Self :: Item > {
33
+ let next = self . next ;
34
+ self . next = next. and_then ( Path :: parent) ;
35
+ next
36
+ }
37
+ }
38
+
39
+ impl FusedIterator for Ancestors < ' _ > { }
Original file line number Diff line number Diff line change 4
4
//!
5
5
//! [`std::path`]: https://doc.rust-lang.org/std/path/index.html
6
6
7
+ mod ancestors;
7
8
mod path;
8
9
mod pathbuf;
9
10
@@ -23,5 +24,6 @@ pub use std::path::MAIN_SEPARATOR;
23
24
#[ doc( inline) ]
24
25
pub use std:: path:: is_separator;
25
26
26
- pub use path:: { Ancestors , Path } ;
27
+ use ancestors:: Ancestors ;
28
+ pub use path:: Path ;
27
29
pub use pathbuf:: PathBuf ;
You can’t perform that action at this time.
0 commit comments