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 44//!
55//! [`std::path`]: https://doc.rust-lang.org/std/path/index.html
66
7+ mod ancestors;
78mod path;
89mod pathbuf;
910
@@ -23,5 +24,6 @@ pub use std::path::MAIN_SEPARATOR;
2324#[ doc( inline) ]
2425pub use std:: path:: is_separator;
2526
26- pub use path:: { Ancestors , Path } ;
27+ use ancestors:: Ancestors ;
28+ pub use path:: Path ;
2729pub use pathbuf:: PathBuf ;
You can’t perform that action at this time.
0 commit comments