Skip to content

Commit

Permalink
Rename WalkNegation to FilterAny.
Browse files Browse the repository at this point in the history
This change renames `WalkNegation` and removes it from the public API in
favor of the `not` iterator combinator.
  • Loading branch information
olson-sean-k committed Nov 4, 2023
1 parent b4fefd8 commit b885195
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/walk/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ struct Anchor {
/// [`WalkEntry`]: crate::WalkEntry
#[cfg_attr(docsrs, doc(cfg(feature = "walk")))]
#[derive(Clone, Debug)]
pub struct WalkNegation {
pub struct FilterAny {
exhaustive: Regex,
nonexhaustive: Regex,
}

impl WalkNegation {
/// Combines glob expressions into a `WalkNegation`.
impl FilterAny {
/// Combines glob expressions into a `FilterAny`.
///
/// This function accepts an [`IntoIterator`] with items that implement [`Combine`], such as
/// [`Glob`] and `&str`.
Expand All @@ -228,7 +228,7 @@ impl WalkNegation {
.map_err(Into::into)?
.into_iter()
.partition::<Vec<_>, _>(|tree| token::is_exhaustive(tree.as_ref().tokens()));
let negation = WalkNegation {
let negation = FilterAny {
exhaustive: crate::any(exhaustive)?.pattern,
nonexhaustive: crate::any(nonexhaustive)?.pattern,
};
Expand Down
4 changes: 2 additions & 2 deletions src/walk/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![cfg(feature = "walk")]

// TODO: Are `cfg(feature = "walk")` attributes redundant on items defined within this module?
// TODO: Are `doc(cfg(feature = "walk"))` attributes redundant on items defined within this module?

mod filter;
mod glob;
mod tree;

pub use crate::walk::glob::{GlobEntry, WalkGlob, WalkNegation};
pub use crate::walk::glob::{GlobEntry, WalkGlob};
pub use crate::walk::tree::{
EntryResidue, FileIterator, FilterEntry, LinkBehavior, Not, WalkBehavior, WalkEntry, WalkError,
WalkTree,
Expand Down
16 changes: 6 additions & 10 deletions src/walk/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::walk::filter::{
self, HierarchicalIterator, Isomeric, SeparatingFilter, SeparatingFilterInput, Separation,
SkipTree, TreeResidue, WalkCancellation,
};
use crate::walk::glob::WalkNegation;
use crate::walk::glob::FilterAny;
use crate::{BuildError, Combine};

pub type FileFiltrate<T> = Result<T, WalkError>;
Expand Down Expand Up @@ -384,10 +384,6 @@ impl SeparatingFilterInput for WalkTree {
type Feed = (Result<WalkEntry, WalkError>, TreeResidue<WalkEntry>);
}

// TODO: This differing behavior is perhaps a bit more intuitive, but less flexible than
// `skip_current_dir`'s behavior. Crucially, `SkipTree` makes it extremely difficult to
// discard a directory in file tree based on its contents, such as some file with a name that
// indicates that a directory should be ignored, etc.
impl SkipTree for WalkTree {
fn skip_tree(&mut self) {
// `IntoIter::skip_current_dir` discards the least recently yielded directory, but
Expand Down Expand Up @@ -543,9 +539,9 @@ pub trait FileIterator:
I: IntoIterator,
I::Item: Combine<'t>,
{
WalkNegation::any(patterns).map(|negation| Not {
FilterAny::any(patterns).map(|filter| Not {
input: self,
negation,
filter,
})
}
}
Expand All @@ -558,7 +554,7 @@ where
}

// TODO: Implement this using combinators provided by the `filter` module and RPITIT once it lands
// in stable Rust. Remove any use of `WalkCancellation::unchecked`.
// in stable Rust. Remove any use of `WalkCancellation::unchecked`.
/// Iterator adaptor that filters [`WalkEntry`]s and controls the traversal of directory trees.
///
/// This adaptor is returned by [`FileIterator::filter_tree`] and in addition to filtering
Expand Down Expand Up @@ -632,7 +628,7 @@ where
#[derive(Clone, Debug)]
pub struct Not<I> {
input: I,
negation: WalkNegation,
filter: FilterAny,
}

impl<T, I> SeparatingFilter for Not<I>
Expand All @@ -650,7 +646,7 @@ where
Ok(separation) => separation
.filter_tree_by_substituent(
WalkCancellation::unchecked(&mut self.input),
|substituent| self.negation.residue(substituent).map(From::from),
|substituent| self.filter.residue(substituent).map(From::from),
)
.map_filtrate(Ok),
Err(error) => error.map(Err).into(),
Expand Down

0 comments on commit b885195

Please sign in to comment.