summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2019-06-18 20:23:47 -0400
committerAndrew Gallant <jamslam@gmail.com>2019-06-18 20:23:47 -0400
commit34677d262246462ce3027ee57be1869a9dc7730a (patch)
tree45d16523c6fed8fa1cbcf3476bae414fb3b2483b
parentd1389db2e39802d5e04dc7b902fd2b1f9f615b01 (diff)
search: a few small touchups
-rw-r--r--src/search.rs47
1 files changed, 20 insertions, 27 deletions
diff --git a/src/search.rs b/src/search.rs
index c866b4bf..8597e80a 100644
--- a/src/search.rs
+++ b/src/search.rs
@@ -315,7 +315,24 @@ pub struct SearchWorker<W> {
impl<W: WriteColor> SearchWorker<W> {
/// Execute a search over the given subject.
pub fn search(&mut self, subject: &Subject) -> io::Result<SearchResult> {
- self.search_impl(subject)
+ let bin =
+ if subject.is_explicit() {
+ self.config.binary_explicit.clone()
+ } else {
+ self.config.binary_implicit.clone()
+ };
+ self.searcher.set_binary_detection(bin);
+
+ let path = subject.path();
+ if subject.is_stdin() {
+ self.search_reader(path, io::stdin().lock())
+ } else if self.should_preprocess(path) {
+ self.search_preprocessor(path)
+ } else if self.should_decompress(path) {
+ self.search_decompress(path)
+ } else {
+ self.search_path(path)
+ }
}
/// Return a mutable reference to the underlying printer.
@@ -341,30 +358,6 @@ impl<W: WriteColor> SearchWorker<W> {
}
}
- /// Search the given subject using the appropriate strategy.
- fn search_impl(&mut self, subject: &Subject) -> io::Result<SearchResult> {
- let bin =
- if subject.is_explicit() {
- self.config.binary_explicit.clone()
- } else {
- self.config.binary_implicit.clone()
- };
- self.searcher.set_binary_detection(bin);
-
- let path = subject.path();
- if subject.is_stdin() {
- let stdin = io::stdin();
- // A `return` here appeases the borrow checker. NLL will fix this.
- return self.search_reader(path, stdin.lock());
- } else if self.should_preprocess(path) {
- self.search_preprocessor(path)
- } else if self.should_decompress(path) {
- self.search_decompress(path)
- } else {
- self.search_path(path)
- }
- }
-
/// Returns true if and only if the given file path should be
/// decompressed before searching.
fn should_decompress(&self, path: &Path) -> bool {
@@ -392,8 +385,8 @@ impl<W: WriteColor> SearchWorker<W> {
&mut self,
path: &Path,
) -> io::Result<SearchResult> {
- let bin = self.config.preprocessor.clone().unwrap();
- let mut cmd = Command::new(&bin);
+ let bin = self.config.preprocessor.as_ref().unwrap();
+ let mut cmd = Command::new(bin);
cmd.arg(path).stdin(Stdio::from(File::open(path)?));
let rdr = self