[−][src]Struct fwatch::Watcher
A watcher instance.
An instance of Watcher keeps track of a vector of watchables and their corresponding states.
Methods
impl<W: Watchable> Watcher<W>
[src]
pub fn new() -> Self
[src]
Create a new watcher instance.
Examples
use fwatch::{BasicTarget, Watcher}; fn main() { let mut watcher: Watcher<BasicTarget> = Watcher::new(); }
pub fn add_target(&mut self, target: W)
[src]
Adds a target to the watcher.
Examples
use fwatch::{BasicTarget, Watcher}; fn main() { let mut watcher : Watcher<BasicTarget> = Watcher::new(); // Watch the "foo.txt" path watcher.add_target(BasicTarget::new("foo.txt")); }
pub fn remove_target(&mut self, index: usize) -> bool
[src]
Remove a target from the watcher.
This function will panic if index is greater than the size of self.states() / self.targets().
Examples
use fwatch::{BasicTarget, Watcher}; fn main() { let mut watcher : Watcher<BasicTarget> = Watcher::new(); // Inserts "foo.txt" at index 0 watcher.add_target(BasicTarget::new("foo.txt")); // Remove "foo.txt" from the watcher assert!(watcher.remove_target(0)); }
pub fn get_state(&self, index: usize) -> Option<&WatchState>
[src]
Attempt to get the state corresponding to the given target index.
Note that this doesn't update the current state.
Examples
use fwatch::{BasicTarget, Watcher, WatchState}; fn main() { let mut watcher : Watcher<BasicTarget> = Watcher::new(); // Watch a file that doesn't exist watcher.add_target(BasicTarget::new("does_not_exist.txt")); assert_eq!(watcher.get_state(0).unwrap(), &WatchState::DoesNotExist); // Watch a file that does exist watcher.add_target(BasicTarget::new("exists.txt")); assert_ne!(watcher.get_state(1).unwrap(), &WatchState::DoesNotExist); }
pub fn get_path(&self, index: usize) -> Option<&PathBuf>
[src]
Attempt to get the path corresponding to the given target index.
Examples
use fwatch::{BasicTarget, Watcher, WatchState}; fn main() { let mut watcher : Watcher<BasicTarget> = Watcher::new(); watcher.add_target(BasicTarget::new("foo.txt")); let path = watcher.get_path(0).unwrap(); assert_eq!(path.to_str().unwrap(), "foo.txt"); }
pub fn watch(&mut self) -> Vec<Transition>
[src]
Observe any state transitions in our targets.
Returns a vector containing the observed state transition for each target.
Examples
use fwatch::{BasicTarget, Watcher, Transition}; fn main() { let mut watcher : Watcher<BasicTarget> = Watcher::new(); // Watch a file that doesn't exist watcher.add_target(BasicTarget::new("does_not_exist.txt")); let results = watcher.watch(); for (index, transition) in watcher.watch().into_iter().enumerate() { // Get a reference to the path and state of the current target let path = watcher.get_path(index).unwrap(); let state = watcher.get_state(index).unwrap(); match transition { Transition::Created => { /* The watched file has been created */ }, Transition::Modified => { /* The watched file has been modified */ }, Transition::Deleted => { /* The watched file has been deleted */ }, Transition::None => { /* None of the above transitions were observed */ }, } } }
Trait Implementations
impl<W: Default + Watchable> Default for Watcher<W>
[src]
impl<W: Debug + Watchable> Debug for Watcher<W>
[src]
Auto Trait Implementations
impl<W> Send for Watcher<W> where
W: Send,
W: Send,
impl<W> Sync for Watcher<W> where
W: Sync,
W: Sync,
impl<W> Unpin for Watcher<W> where
W: Unpin,
W: Unpin,
impl<W> UnwindSafe for Watcher<W> where
W: UnwindSafe,
W: UnwindSafe,
impl<W> RefUnwindSafe for Watcher<W> where
W: RefUnwindSafe,
W: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,