Skip to content

Instantly share code, notes, and snippets.

@hauleth
Created June 30, 2016 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hauleth/dc7602712cf0db617d00dcdb0237fe4a to your computer and use it in GitHub Desktop.
Save hauleth/dc7602712cf0db617d00dcdb0237fe4a to your computer and use it in GitHub Desktop.
extern crate rayon;
extern crate regex;
extern crate scan_dir;
use rayon::prelude::*;
use regex::Regex;
use scan_dir::ScanDir;
use std::env;
use std::fs::File;
use std::io::{BufReader, BufRead};
fn main() {
let query = env::args().skip(1).next().unwrap().to_owned();
let regex = Regex::new(&*query).unwrap();
let files: Vec<_> = ScanDir::files()
.walk("src", |iter| iter.map(|(entry, _)| entry.path()).collect())
.unwrap();
files
.par_iter()
.map(File::open)
.map(Result::unwrap)
.map(BufReader::new)
.map(BufRead::lines)
.map(|lines| {
lines
.flat_map(Result::ok)
.filter(|line| regex.is_match(line))
.collect::<Vec<_>>()
})
.for_each(|file| println!("{:?}", file));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment