common/rust: add Path::parents helper method
This commit is contained in:
parent
23418f98be
commit
5d846eb88c
1 changed files with 16 additions and 1 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
mod section_range;
|
mod section_range;
|
||||||
|
|
||||||
use std::mem;
|
use std::{mem, path::Path};
|
||||||
|
|
||||||
pub use section_range::{EmptyRange, InvalidSectionString, SectionRange};
|
pub use section_range::{EmptyRange, InvalidSectionString, SectionRange};
|
||||||
|
|
||||||
|
@ -61,3 +61,18 @@ impl<T> Iterator for UpToTwoIter<T> {
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait PathExt {
|
||||||
|
type Iter<'a>: Iterator<Item = &'a Path>
|
||||||
|
where
|
||||||
|
Self: 'a;
|
||||||
|
fn parents(&self) -> Self::Iter<'_>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PathExt for Path {
|
||||||
|
type Iter<'a> = std::iter::Successors<&'a Path, for<'p> fn(&&'p Path) -> Option<&'p Path>>;
|
||||||
|
|
||||||
|
fn parents(&self) -> Self::Iter<'_> {
|
||||||
|
std::iter::successors(Some(self), |dir| dir.parent())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue