Skip to content

Commit

Permalink
Strip prefixes in WalkEntrys.
Browse files Browse the repository at this point in the history
This change makes stripped paths available to `FileIterator` filters in
both filtrate and residue by supporting a stripped path in `WalkEntry`s.
  • Loading branch information
olson-sean-k committed Oct 31, 2023
1 parent f8768a6 commit 6cef258
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 107 deletions.
56 changes: 24 additions & 32 deletions src/walk/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,6 @@ impl<T, U> Feed for (T, U) {
type Residue = U;
}

// TODO: Remove this?
pub trait Isomorphic: Feed
where
SeparationFiltrate<Self>: Isomer<SeparationResidue<Self>>,
for<'a> SeparationResidue<Self>:
'a + Isomer<SeparationFiltrate<Self>, Substituent<'a> = SeparationSubstituent<'a, Self>>,
{
}

impl<F, R, S> Isomorphic for S
where
F: Isomer<R>,
for<'a> R: 'a + Isomer<F, Substituent<'a> = <F as Isomer<R>>::Substituent<'a>>,
S: Feed<Filtrate = F, Residue = R>,
{
}

pub trait Isomer<T>: Sized {
type Substituent<'a>
where
Expand All @@ -180,9 +163,7 @@ impl<S> Separation<S>
where
S: Feed,
{
// TODO: Provide a trait-based and intentionally very limited way to implement a base
// `Feed` that constructs a `Filtrate<T>` from unfiltered `Iterator` items of `T`.
pub(in crate::walk) fn from_inner_filtrate(filtrate: S::Filtrate) -> Self {
fn from_inner_filtrate(filtrate: S::Filtrate) -> Self {
Separation::Filtrate(Filtrate::new(filtrate))
}

Expand Down Expand Up @@ -276,7 +257,11 @@ where
}
}

pub fn filter_isomer_tree<I, F>(self, cancellation: WalkCancellation<'_, I>, f: F) -> Self
pub fn filter_tree_by_substituent<I, F>(
self,
cancellation: WalkCancellation<'_, I>,
f: F,
) -> Self
where
U: 'static + From<S::Filtrate>,
S::Filtrate: Isomer<TreeResidue<U>>,
Expand Down Expand Up @@ -339,21 +324,27 @@ where
}
}

// TODO: Remove this?
impl<S> Feed for Separation<S>
where
S: Feed,
{
type Filtrate = S::Filtrate;
type Residue = S::Residue;
}

pub trait SeparatingFilter {
type Feed: Feed;

fn feed(&mut self) -> Option<Separation<Self::Feed>>;
}

impl<I> SeparatingFilter for I
where
I: SeparatingFilterInput,
{
type Feed = <I as SeparatingFilterInput>::Feed;

fn feed(&mut self) -> Option<Separation<Self::Feed>> {
self.next().map(Separation::from_inner_filtrate)
}
}

pub trait SeparatingFilterInput: Iterator {
type Feed: Feed<Filtrate = Self::Item>;
}

pub trait SkipTree {
fn skip_tree(&mut self);
}
Expand All @@ -366,8 +357,9 @@ where
I: SkipTree,
{
fn skip_tree(&mut self) {
// Client code is only able to move a `WalkCancellation` into `Filtered::filter_map_tree`,
// at which point the filtered item should be the current item of the iterator.
// Client code is only able to move a `WalkCancellation` into
// `Separation::filter_map_tree`, at which point the filtered item should be the current
// item of the iterator.
self.0.skip_tree()
}
}
Expand Down

0 comments on commit 6cef258

Please sign in to comment.