1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Utilities for [`Action`].
use std::{collections::HashSet, path::Path};
use watchexec::{action::Action, event::Event, signal::source::MainSignal};
/// Utility struct for [`Action`].
pub struct WAction(Action);
impl WAction {
/// Create a new [`WAction`].
pub fn new(action: Action) -> Self {
Self(action)
}
/// Return the internal action by consuming `self`.
pub fn take(self) -> Action {
self.0
}
/// Returns whether the action includes [`MainSignal::Interrupt`].
pub fn is_interrupt(&self) -> bool {
self.is_any_signal(MainSignal::Interrupt)
}
/// Returns whether the action includes [`MainSignal::Terminate`].
pub fn is_terminate(&self) -> bool {
self.is_any_signal(MainSignal::Terminate)
}
/// Get all the unique paths in the action event paths.
pub fn get_unique_paths(&self) -> HashSet<&Path> {
let mut hashset = HashSet::new();
for (path, _) in self.0.events.iter().flat_map(Event::paths) {
hashset.insert(path);
}
hashset
}
/// Returns whether any signal includes the given signal in the events list.
fn is_any_signal(&self, signal: MainSignal) -> bool {
self.0
.events
.iter()
.flat_map(Event::signals)
.any(|sig| sig == signal)
}
}