use std::time::Duration;
pub const DEFAULT_MAX_FSEVENT_PATHS: usize = 128;
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub struct WatchMode {
pub recursive_mode: RecursiveMode,
pub target_mode: TargetMode,
}
impl WatchMode {
#[must_use]
pub fn recursive() -> Self {
Self {
recursive_mode: RecursiveMode::Recursive,
target_mode: TargetMode::TrackPath,
}
}
#[must_use]
pub fn non_recursive() -> Self {
Self {
recursive_mode: RecursiveMode::NonRecursive,
target_mode: TargetMode::TrackPath,
}
}
pub(crate) fn upgrade_with(&mut self, other: WatchMode) {
self.recursive_mode = self.recursive_mode.upgraded_with(other.recursive_mode);
self.target_mode = self.target_mode.upgraded_with(other.target_mode);
}
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub enum RecursiveMode {
Recursive,
NonRecursive,
}
impl RecursiveMode {
#[expect(clippy::trivially_copy_pass_by_ref)]
pub(crate) fn is_recursive(&self) -> bool {
match *self {
RecursiveMode::Recursive => true,
RecursiveMode::NonRecursive => false,
}
}
pub(crate) fn upgraded_with(self, other: Self) -> Self {
match self {
RecursiveMode::Recursive => self,
RecursiveMode::NonRecursive => {
if other == RecursiveMode::Recursive {
other
} else {
self
}
}
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub enum TargetMode {
TrackPath,
NoTrack,
}
impl TargetMode {
pub(crate) fn upgraded_with(self, other: Self) -> Self {
match self {
TargetMode::TrackPath => self,
TargetMode::NoTrack => {
if other == TargetMode::TrackPath {
other
} else {
self
}
}
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub struct Config {
poll_interval: Option<Duration>,
compare_contents: bool,
follow_symlinks: bool,
max_fsevent_paths: usize,
}
impl Config {
#[must_use]
pub fn with_poll_interval(mut self, dur: Duration) -> Self {
self.poll_interval = Some(dur);
self
}
#[must_use]
pub fn poll_interval(&self) -> Option<Duration> {
self.poll_interval
}
#[must_use]
pub fn with_manual_polling(mut self) -> Self {
self.poll_interval = None;
self
}
#[must_use]
pub fn with_compare_contents(mut self, compare_contents: bool) -> Self {
self.compare_contents = compare_contents;
self
}
#[must_use]
pub fn compare_contents(&self) -> bool {
self.compare_contents
}
#[must_use]
pub fn with_follow_symlinks(mut self, follow_symlinks: bool) -> Self {
self.follow_symlinks = follow_symlinks;
self
}
#[must_use]
pub fn follow_symlinks(&self) -> bool {
self.follow_symlinks
}
#[must_use]
pub fn with_max_fsevent_paths(mut self, max_paths: usize) -> Self {
self.max_fsevent_paths = max_paths;
self
}
#[must_use]
pub fn max_fsevent_paths(&self) -> usize {
self.max_fsevent_paths
}
}
impl Default for Config {
fn default() -> Self {
Self {
poll_interval: Some(Duration::from_secs(30)),
compare_contents: false,
follow_symlinks: true,
max_fsevent_paths: DEFAULT_MAX_FSEVENT_PATHS,
}
}
}