Run formatter

This commit is contained in:
Félix Saparelli 2019-10-28 00:31:52 +13:00
parent 10fac30c7b
commit a3c5bd7201
No known key found for this signature in database
GPG key ID: 25940898BB90EA51
8 changed files with 58 additions and 45 deletions

View file

@ -14,8 +14,8 @@
//! .unwrap();
//! ```
use clap::{App, Arg, Error};
use crate::error;
use clap::{App, Arg, Error};
use std::{
ffi::OsString,
path::{PathBuf, MAIN_SEPARATOR},
@ -216,11 +216,13 @@ where
if let Some(extensions) = args.values_of("extensions") {
for exts in extensions {
filters.extend(
exts.split(',')
.filter_map(|ext| if ext.is_empty() { None } else {
Some(format!("*.{}", ext.replace(".", ""))) }),
);
filters.extend(exts.split(',').filter_map(|ext| {
if ext.is_empty() {
None
} else {
Some(format!("*.{}", ext.replace(".", "")))
}
}));
}
}

View file

@ -55,9 +55,10 @@ impl<'a, T> From<PoisonError<T>> for Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let (error_type, error) = match self {
Self::Canonicalization(path, err) => {
("Path", format!("couldn't canonicalize '{}':\n{}", path, err))
}
Self::Canonicalization(path, err) => (
"Path",
format!("couldn't canonicalize '{}':\n{}", path, err),
),
Self::Clap(err) => ("Argument", err.to_string()),
Self::Glob(err) => ("Globset", err.to_string()),
Self::Io(err) => ("I/O", err.to_string()),

View file

@ -55,9 +55,9 @@ pub fn load(paths: &[PathBuf]) -> Gitignore {
let gitignore_path = p.join(".gitignore");
if gitignore_path.exists() {
if let Ok(f) = GitignoreFile::new(&gitignore_path) {
debug!("Loaded {:?}", gitignore_path);
files.push(f);
} else {
debug!("Loaded {:?}", gitignore_path);
files.push(f);
} else {
debug!("Unable to load {:?}", gitignore_path);
}
}
@ -82,8 +82,8 @@ pub fn load(paths: &[PathBuf]) -> Gitignore {
}
impl Gitignore {
const fn new(files: Vec<GitignoreFile>) -> Self{
Self{ files }
const fn new(files: Vec<GitignoreFile>) -> Self {
Self { files }
}
pub fn is_excluded(&self, path: &Path) -> bool {
@ -143,7 +143,7 @@ impl GitignoreFile {
patterns.push(p);
}
Ok(Self{
Ok(Self {
set: builder.build()?,
patterns,
root: root.to_owned(),
@ -181,14 +181,19 @@ impl GitignoreFile {
fn parse(contents: &[&str]) -> Vec<Pattern> {
contents
.iter()
.filter_map(|l| if !l.is_empty() && !l.starts_with('#') {
Some(Pattern::parse(l)) } else { None })
.filter_map(|l| {
if !l.is_empty() && !l.starts_with('#') {
Some(Pattern::parse(l))
} else {
None
}
})
.collect()
}
}
impl Pattern {
fn parse(pattern: &str) -> Self{
fn parse(pattern: &str) -> Self {
let mut normalized = String::from(pattern);
let pattern_type = if normalized.starts_with('!') {
@ -213,7 +218,7 @@ impl Pattern {
normalized.remove(0);
}
Self{
Self {
pattern: normalized,
pattern_type,
anchored,
@ -222,13 +227,13 @@ impl Pattern {
}
impl From<globset::Error> for Error {
fn from(error: globset::Error) -> Self{
fn from(error: globset::Error) -> Self {
Self::GlobSet(error)
}
}
impl From<io::Error> for Error {
fn from(error: io::Error) -> Self{
fn from(error: io::Error) -> Self {
Self::Io(error)
}
}

View file

@ -55,10 +55,10 @@ pub fn load(paths: &[PathBuf]) -> Ignore {
let ignore_path = p.join(".ignore");
if ignore_path.exists() {
if let Ok(f) = IgnoreFile::new(&ignore_path) {
debug!("Loaded {:?}", ignore_path);
files.push(f);
} else {
debug!("Unable to load {:?}", ignore_path);
debug!("Loaded {:?}", ignore_path);
files.push(f);
} else {
debug!("Unable to load {:?}", ignore_path);
}
}
}
@ -174,7 +174,13 @@ impl IgnoreFile {
fn parse(contents: &[&str]) -> Vec<Pattern> {
contents
.iter()
.filter_map(|l| if !l.is_empty() && !l.starts_with('#') { Some(Pattern::parse(l)) } else { None })
.filter_map(|l| {
if !l.is_empty() && !l.starts_with('#') {
Some(Pattern::parse(l))
} else {
None
}
})
.collect()
}
}

View file

@ -1,7 +1,7 @@
use crate::error;
use crate::gitignore::Gitignore;
use globset::{Glob, GlobSet, GlobSetBuilder};
use crate::ignore::Ignore;
use globset::{Glob, GlobSet, GlobSetBuilder};
use std::path::Path;
pub struct NotificationFilter {

View file

@ -59,10 +59,10 @@ fn wrap_commands(cmd: &Vec<String>) -> Vec<String> {
#[cfg(target_family = "unix")]
mod imp {
//use super::wrap_commands;
use nix::libc::*;
use nix::{self, Error};
use crate::pathop::PathOp;
use crate::signal::Signal;
use nix::libc::*;
use nix::{self, Error};
use std::io::{self, Result};
use std::process::Command;
use std::sync::*;
@ -85,8 +85,8 @@ mod imp {
impl Process {
pub fn new(cmd: &[String], updated_paths: &[PathOp], no_shell: bool) -> Result<Self> {
use nix::unistd::*;
use std::convert::TryInto;
use std::os::unix::process::CommandExt;
use std::convert::TryInto;
// Assemble command to run.
// This is either the first argument from cmd (if no_shell was given) or "sh".
@ -112,16 +112,16 @@ mod imp {
command.env(name, val);
}
unsafe { command.pre_exec(|| setsid().map_err(from_nix_error).map(|_| ())); }
command
.spawn()
.and_then(|p| {
Ok(Self {
pgid: p.id().try_into().unwrap(),
lock: Mutex::new(false),
cvar: Condvar::new(),
})
unsafe {
command.pre_exec(|| setsid().map_err(from_nix_error).map(|_| ()));
}
command.spawn().and_then(|p| {
Ok(Self {
pgid: p.id().try_into().unwrap(),
lock: Mutex::new(false),
cvar: Condvar::new(),
})
})
}
pub fn reap(&self) {
@ -131,8 +131,7 @@ mod imp {
let mut finished = true;
loop {
match waitpid(Pid::from_raw(-self.pgid), Some(WaitPidFlag::WNOHANG)) {
Ok(WaitStatus::Exited(_, _)) | Ok(WaitStatus::Signaled(_, _, _)) => {
}
Ok(WaitStatus::Exited(_, _)) | Ok(WaitStatus::Signaled(_, _, _)) => {}
Ok(_) => {
finished = false;
break;
@ -178,9 +177,9 @@ mod imp {
#[cfg(target_family = "windows")]
mod imp {
//use super::wrap_commands;
use kernel32::*;
use crate::pathop::PathOp;
use crate::signal::Signal;
use kernel32::*;
use std::io;
use std::io::Result;
use std::mem;

View file

@ -6,6 +6,7 @@ use crate::notification_filter::NotificationFilter;
use crate::pathop::PathOp;
use crate::process::{self, Process};
use crate::signal::{self, Signal};
use crate::watcher::{Event, Watcher};
use std::{
collections::HashMap,
fs::canonicalize,
@ -16,7 +17,6 @@ use std::{
},
time::Duration,
};
use crate::watcher::{Event, Watcher};
fn init_logger(debug: bool) {
let mut log_builder = env_logger::Builder::new();

View file

@ -100,7 +100,7 @@ where
set_handler(handler);
#[allow(unsafe_code)]
#[allow(unsafe_code)]
unsafe {
let _ = sigaction(
SIGCHLD,
@ -126,7 +126,7 @@ where
let default_action =
SigAction::new(SigHandler::SigDfl, SaFlags::empty(), SigSet::empty());
#[allow(unsafe_code)]
#[allow(unsafe_code)]
unsafe {
let _ = sigaction(signal, &default_action);
}