diff --git a/common/rust/src/lib.rs b/common/rust/src/lib.rs index 457791d..8be2e20 100644 --- a/common/rust/src/lib.rs +++ b/common/rust/src/lib.rs @@ -2,7 +2,7 @@ mod section_range; -use std::mem; +use std::{mem, path::Path}; pub use section_range::{EmptyRange, InvalidSectionString, SectionRange}; @@ -61,3 +61,18 @@ impl Iterator for UpToTwoIter { ret } } + +pub trait PathExt { + type Iter<'a>: Iterator + 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()) + } +}