cleanup: add result alias

This commit is contained in:
Aleksey Kladov 2019-01-26 16:40:24 +03:00
parent 390a20787e
commit 3ce531f95d

View file

@ -1,11 +1,11 @@
use std::{ use std::{
fs, fs,
thread,
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::{mpsc, Arc}, sync::{mpsc, Arc},
thread,
time::Duration, time::Duration,
}; };
use crossbeam_channel::{Receiver, Sender, SendError}; use crossbeam_channel::{Receiver, Sender};
use relative_path::RelativePathBuf; use relative_path::RelativePathBuf;
use thread_worker::WorkerHandle; use thread_worker::WorkerHandle;
use walkdir::WalkDir; use walkdir::WalkDir;
@ -14,6 +14,8 @@ use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher as _Watc
use crate::{RootConfig, Roots, VfsRoot}; use crate::{RootConfig, Roots, VfsRoot};
type Result<T> = std::result::Result<T, crossbeam_channel::SendError<TaskResult>>;
pub(crate) enum Task { pub(crate) enum Task {
AddRoot { AddRoot {
root: VfsRoot, root: VfsRoot,
@ -112,11 +114,7 @@ impl Worker {
} }
} }
fn watch_root( fn watch_root(woker: &WatcherCtx, root: VfsRoot, config: Arc<RootConfig>) -> Result<()> {
woker: &WatcherCtx,
root: VfsRoot,
config: Arc<RootConfig>,
) -> Result<(), SendError<TaskResult>> {
let mut guard = woker.watcher.lock(); let mut guard = woker.watcher.lock();
log::debug!("loading {} ...", config.root.as_path().display()); log::debug!("loading {} ...", config.root.as_path().display());
let files = watch_recursive(guard.as_mut(), config.root.as_path(), &*config) let files = watch_recursive(guard.as_mut(), config.root.as_path(), &*config)
@ -142,7 +140,7 @@ struct WatcherCtx {
} }
impl WatcherCtx { impl WatcherCtx {
fn handle_debounced_event(&self, ev: DebouncedEvent) -> Result<(), SendError<TaskResult>> { fn handle_debounced_event(&self, ev: DebouncedEvent) -> Result<()> {
match ev { match ev {
DebouncedEvent::NoticeWrite(_) DebouncedEvent::NoticeWrite(_)
| DebouncedEvent::NoticeRemove(_) | DebouncedEvent::NoticeRemove(_)
@ -173,7 +171,7 @@ impl WatcherCtx {
Ok(()) Ok(())
} }
fn handle_change(&self, path: PathBuf, kind: ChangeKind) -> Result<(), SendError<TaskResult>> { fn handle_change(&self, path: PathBuf, kind: ChangeKind) -> Result<()> {
let (root, rel_path) = match self.roots.find(&path) { let (root, rel_path) = match self.roots.find(&path) {
None => return Ok(()), None => return Ok(()),
Some(it) => it, Some(it) => it,