mirror of https://github.com/sharkdp/fd.git
chore: format code via rustfmt
This commit is contained in:
parent
2ebef2d46f
commit
6407dc4eb4
|
@ -6,17 +6,21 @@
|
||||||
// notice may not be copied, modified, or distributed except
|
// notice may not be copied, modified, or distributed except
|
||||||
// according to those terms.
|
// according to those terms.
|
||||||
|
|
||||||
|
use super::CommandTemplate;
|
||||||
|
use internal::error;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::mpsc::Receiver;
|
use std::sync::mpsc::Receiver;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use::walk::WorkerResult;
|
use walk::WorkerResult;
|
||||||
use::internal::error;
|
|
||||||
use super::CommandTemplate;
|
|
||||||
|
|
||||||
/// An event loop that listens for inputs from the `rx` receiver. Each received input will
|
/// An event loop that listens for inputs from the `rx` receiver. Each received input will
|
||||||
/// generate a command with the supplied command template. The generated command will then
|
/// generate a command with the supplied command template. The generated command will then
|
||||||
/// be executed, and this process will continue until the receiver's sender has closed.
|
/// be executed, and this process will continue until the receiver's sender has closed.
|
||||||
pub fn job(rx: Arc<Mutex<Receiver<WorkerResult>>>, cmd: Arc<CommandTemplate>, out_perm: Arc<Mutex<()>>) {
|
pub fn job(
|
||||||
|
rx: Arc<Mutex<Receiver<WorkerResult>>>,
|
||||||
|
cmd: Arc<CommandTemplate>,
|
||||||
|
out_perm: Arc<Mutex<()>>,
|
||||||
|
) {
|
||||||
loop {
|
loop {
|
||||||
// Create a lock on the shared receiver for this thread.
|
// Create a lock on the shared receiver for this thread.
|
||||||
let lock = rx.lock().unwrap();
|
let lock = rx.lock().unwrap();
|
||||||
|
@ -24,13 +28,11 @@ pub fn job(rx: Arc<Mutex<Receiver<WorkerResult>>>, cmd: Arc<CommandTemplate>, ou
|
||||||
// Obtain the next path from the receiver, else if the channel
|
// Obtain the next path from the receiver, else if the channel
|
||||||
// has closed, exit from the loop
|
// has closed, exit from the loop
|
||||||
let value: PathBuf = match lock.recv() {
|
let value: PathBuf = match lock.recv() {
|
||||||
Ok(value) => {
|
Ok(value) => match value {
|
||||||
match value {
|
|
||||||
WorkerResult::Entry(val) => val,
|
WorkerResult::Entry(val) => val,
|
||||||
WorkerResult::Error(err) => {
|
WorkerResult::Error(err) => {
|
||||||
error(&format!("{}", err));
|
error(&format!("{}", err));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Err(_) => break,
|
Err(_) => break,
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,7 +39,7 @@ enum ReceiverMode {
|
||||||
/// The Worker threads can result in a valid entry having PathBuf or an error.
|
/// The Worker threads can result in a valid entry having PathBuf or an error.
|
||||||
pub enum WorkerResult {
|
pub enum WorkerResult {
|
||||||
Entry(PathBuf),
|
Entry(PathBuf),
|
||||||
Error(ignore::Error)
|
Error(ignore::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recursively scan the given search path for files / pathnames matching the pattern.
|
/// Recursively scan the given search path for files / pathnames matching the pattern.
|
||||||
|
@ -300,7 +300,9 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) {
|
||||||
if let Some(search_str) = search_str_o {
|
if let Some(search_str) = search_str_o {
|
||||||
if pattern.is_match(&*search_str) {
|
if pattern.is_match(&*search_str) {
|
||||||
// TODO: take care of the unwrap call
|
// TODO: take care of the unwrap call
|
||||||
tx_thread.send(WorkerResult::Entry(entry_path.to_owned())).unwrap()
|
tx_thread
|
||||||
|
.send(WorkerResult::Entry(entry_path.to_owned()))
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue