Skip to content

Commit

Permalink
Decompose walk module into sub-modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
olson-sean-k committed Nov 2, 2023
1 parent 18202cb commit 74b039c
Show file tree
Hide file tree
Showing 6 changed files with 1,108 additions and 1,178 deletions.
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod diagnostics;
mod encode;
mod rule;
mod token;
mod walk;
pub mod walk;

#[cfg(feature = "miette")]
use miette::Diagnostic;
Expand All @@ -53,13 +53,11 @@ use thiserror::Error;
use crate::encode::CompileError;
use crate::rule::{Checked, RuleError};
use crate::token::{InvariantText, ParseError, Token, TokenTree, Tokenized};
#[cfg(feature = "walk")]
use crate::walk::WalkError;

pub use crate::capture::MatchedText;
pub use crate::diagnostics::{LocatedError, Span};
#[cfg(feature = "walk")]
pub use crate::walk::{
FileIterator, FilterTree, GlobEntry, LinkBehavior, WalkBehavior, WalkError, WalkNegation,
};

#[cfg(windows)]
const PATHS_ARE_CASE_INSENSITIVE: bool = true;
Expand Down
18 changes: 5 additions & 13 deletions src/walk/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,13 @@ mod state {

impl<K, T> TypeState<K, Option<T>> {
pub fn transpose(self) -> Option<TypeState<K, T>> {
match self.inner {
Some(inner) => Some(TypeState::new(inner)),
_ => None,
}
self.inner.map(TypeState::new)
}
}

impl<K, T, E> TypeState<K, Result<T, E>> {
pub fn transpose(self) -> Result<TypeState<K, T>, TypeState<K, E>> {
match self.inner {
Ok(inner) => Ok(TypeState::new(inner)),
Err(error) => Err(TypeState::new(error)),
}
self.inner.map(TypeState::new).map_err(TypeState::new)
}
}

Expand Down Expand Up @@ -268,9 +262,8 @@ where
impl<T, R> Separation<(Option<T>, R)> {
pub fn transpose_filtrate(self) -> Option<Separation<(T, R)>> {
match self {
Separation::Filtrate(filtrate) => match filtrate.into_inner() {
Some(filtrate) => Some(Filtrate::new(filtrate).into()),
_ => None,
Separation::Filtrate(filtrate) => {
filtrate.into_inner().map(Filtrate::new).map(From::from)
},
Separation::Residue(residue) => Some(residue.into()),
}
Expand Down Expand Up @@ -368,8 +361,7 @@ pub enum TreeResidue<T> {
impl<T> AsRef<T> for TreeResidue<T> {
fn as_ref(&self) -> &T {
match self {
TreeResidue::Node(ref residue) => residue,
TreeResidue::Tree(ref residue) => residue,
TreeResidue::Node(ref residue) | TreeResidue::Tree(ref residue) => residue,
}
}
}
Expand Down
Loading

0 comments on commit 74b039c

Please sign in to comment.