Skip to main content

Crate parex

Crate parex 

Source
Expand description

§parex

Blazing-fast parallel search engine — generic, embeddable, zero opinions.

parex is a parallel execution framework. It owns the walk engine, the contracts (Source, Matcher), the error type, and the builder API. It does not own filesystem-specific logic, built-in matchers, or output formatting — those belong to the caller.

§Quick Start

use parex::{Source, Entry, EntryKind, ParexError, Matcher};
use parex::engine::WalkConfig;

// A minimal in-memory source for demonstration
struct NameSource(Vec<&'static str>);

impl Source for NameSource {
    fn walk(&self, _config: &WalkConfig) -> Box<dyn Iterator<Item = Result<Entry, ParexError>>> {
        let entries = self.0.iter().map(|name| Ok(Entry {
            path:     name.into(),
            kind:     EntryKind::File,
            depth:    0,
            metadata: None,
        })).collect::<Vec<_>>();
        Box::new(entries.into_iter())
    }
}

let results = parex::search()
    .source(NameSource(vec!["invoice_jan.txt", "invoice_feb.txt", "report.txt"]))
    .matching("invoice")
    .collect_paths(true)
    .run()
    .unwrap();

assert_eq!(results.matches, 2);
println!("Found {} matches in {:.3}s",
    results.matches,
    results.stats.duration.as_secs_f64()
);

§Custom Sources and Matchers

Implement Source to search anything traversable:

use parex::{Source, Entry, EntryKind, ParexError};
use parex::engine::WalkConfig;

struct VecSource(Vec<String>);

impl Source for VecSource {
    fn walk(&self, _config: &WalkConfig) -> Box<dyn Iterator<Item = Result<Entry, ParexError>>> {
        let entries = self.0.iter().map(|name| Ok(Entry {
            path:     name.into(),
            kind:     EntryKind::File,
            depth:    0,
            metadata: None,
        })).collect::<Vec<_>>();
        Box::new(entries.into_iter())
    }
}

Implement Matcher for custom matching logic:

use parex::{Matcher, Entry};

struct ExtensionMatcher(String);

impl Matcher for ExtensionMatcher {
    fn is_match(&self, entry: &Entry) -> bool {
        entry.path
            .extension()
            .map(|e| e.eq_ignore_ascii_case(&self.0))
            .unwrap_or(false)
    }
}

Modules§

engine

Structs§

Entry
A single item produced by a Source during traversal.
Results
The output of a completed search.
ScanStats
Performance statistics for a completed scan.
SearchBuilder
Entry point for configuring and executing a parex search.

Enums§

EntryKind
The kind of a traversed entry.
ParexError

Traits§

Matcher
Determines whether an entry is a match.
Source
A source of entries to search through.

Functions§

search
Create a new SearchBuilder to configure and run a search.