mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-11-29 05:57:07 +02:00
repo: move all source code in crates directory
The top-level listing was just getting a bit too long for my taste. So put all of the code in one directory and shrink the large top-level mess to a small top-level mess. NOTE: This commit only contains renames. The subsequent commit will actually make ripgrep build again. We do it this way with the naive hope that this will make it easier for git history to track the renames. Sigh.
This commit is contained in:
37
crates/searcher/examples/search-stdin.rs
Normal file
37
crates/searcher/examples/search-stdin.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
extern crate grep_regex;
|
||||
extern crate grep_searcher;
|
||||
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::io;
|
||||
use std::process;
|
||||
|
||||
use grep_regex::RegexMatcher;
|
||||
use grep_searcher::sinks::UTF8;
|
||||
use grep_searcher::Searcher;
|
||||
|
||||
fn main() {
|
||||
if let Err(err) = example() {
|
||||
eprintln!("{}", err);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
fn example() -> Result<(), Box<dyn Error>> {
|
||||
let pattern = match env::args().nth(1) {
|
||||
Some(pattern) => pattern,
|
||||
None => {
|
||||
return Err(From::from(format!("Usage: search-stdin <pattern>")))
|
||||
}
|
||||
};
|
||||
let matcher = RegexMatcher::new(&pattern)?;
|
||||
Searcher::new().search_reader(
|
||||
&matcher,
|
||||
io::stdin(),
|
||||
UTF8(|lnum, line| {
|
||||
print!("{}:{}", lnum, line);
|
||||
Ok(true)
|
||||
}),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user