Skip to content

Commit

Permalink
Add more trait impls, in particular Debug
Browse files Browse the repository at this point in the history
This makes it easier to derive traits when they contain a notify type.
  • Loading branch information
tmfink authored and 0xpr03 committed Jan 5, 2022
1 parent adbbd33 commit 704e6d6
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 12 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -11,11 +11,13 @@
- CHANGE: Avoid stating the watched path for non-recursive watches with inotify [#256]
- FIX: Report events promptly on Linux, even when many occur in rapid succession. [#268]
- FIX: Remove `anymap`, and replace event attributes with an opaque type. [#306]
- CHANGE: Hide fsevent::{CFRunLoopIsWaiting,callback}, fix clippy lint warnings [#312]
- CHANGE: Hide `fsevent::{CFRunLoopIsWaiting,callback}`, fix clippy lint warnings [#312]
- CHANGE: Add more trait impls for public types, in particular `Debug` [#377]

[#268]: https://github.com/notify-rs/notify/pull/268
[#306]: https://github.com/notify-rs/notify/pull/306
[#312]: https://github.com/notify-rs/notify/pull/312
[#377]: https://github.com/notify-rs/notify/pull/377

## unreleased

Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Expand Up @@ -3,7 +3,7 @@
use std::time::Duration;

/// Indicates whether only the provided directory or its sub-directories as well should be watched
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub enum RecursiveMode {
/// Watch all sub-directories as well, including directories created after installing the watch
Recursive,
Expand All @@ -24,7 +24,7 @@ impl RecursiveMode {
/// Runtime configuration items for watchers.
///
/// See the [`Watcher::configure`](../trait.Watcher.html#tymethod.configure) method for usage.
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Config {
/// Enable or disable emitting precise event classification.
///
Expand Down
16 changes: 8 additions & 8 deletions src/event.rs
Expand Up @@ -12,7 +12,7 @@ use std::{
use serde::{Deserialize, Serialize};

/// An event describing open or close operations on files.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub enum AccessMode {
Expand All @@ -33,7 +33,7 @@ pub enum AccessMode {
}

/// An event describing non-mutating access operations on files.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "kind", content = "mode"))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
Expand All @@ -55,7 +55,7 @@ pub enum AccessKind {
}

/// An event describing creation operations on files.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "kind"))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
Expand All @@ -74,7 +74,7 @@ pub enum CreateKind {
}

/// An event emitted when the data content of a file is changed.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub enum DataChange {
Expand All @@ -92,7 +92,7 @@ pub enum DataChange {
}

/// An event emitted when the metadata of a file or folder is changed.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub enum MetadataKind {
Expand Down Expand Up @@ -122,7 +122,7 @@ pub enum MetadataKind {
}

/// An event emitted when the name of a file or folder is changed.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub enum RenameMode {
Expand Down Expand Up @@ -169,7 +169,7 @@ pub enum ModifyKind {
}

/// An event describing removal operations on files.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "kind"))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
Expand Down Expand Up @@ -479,7 +479,7 @@ impl EventAttributes {
///
/// This attribute is used to flag certain kinds of events that Notify either marks or generates in
/// particular ways.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub enum Flag {
/*
Expand Down
1 change: 1 addition & 0 deletions src/inotify.rs
Expand Up @@ -42,6 +42,7 @@ struct EventLoop {
}

/// Watcher implementation based on inotify
#[derive(Debug)]
pub struct INotifyWatcher {
channel: crossbeam_channel::Sender<EventLoopMsg>,
waker: Arc<mio::Waker>,
Expand Down
1 change: 1 addition & 0 deletions src/kqueue.rs
Expand Up @@ -37,6 +37,7 @@ struct EventLoop {
}

/// Watcher implementation based on inotify
#[derive(Debug)]
pub struct KqueueWatcher {
channel: crossbeam_channel::Sender<EventLoopMsg>,
waker: Arc<mio::Waker>,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -186,7 +186,7 @@ impl EventHandler for std::sync::mpsc::Sender<Result<Event>> {
}

/// Watcher kind enumeration
#[derive(Debug,PartialEq,Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum WatcherKind {
/// inotify backend (linux)
Expand Down
1 change: 1 addition & 0 deletions src/null.rs
Expand Up @@ -8,6 +8,7 @@ use std::path::Path;
/// Stub `Watcher` implementation
///
/// Events are never delivered from this watcher.
#[derive(Debug)]
pub struct NullWatcher;

impl Watcher for NullWatcher {
Expand Down
13 changes: 13 additions & 0 deletions src/poll.rs
Expand Up @@ -7,6 +7,7 @@ use super::event::*;
use super::{Error, EventHandler, RecursiveMode, Result, Watcher};
use filetime::FileTime;
use std::collections::HashMap;
use std::fmt::Debug;
use std::fs;
use std::path::{Path, PathBuf};
use std::sync::{
Expand All @@ -17,11 +18,13 @@ use std::thread;
use std::time::{Duration, Instant};
use walkdir::WalkDir;

#[derive(Debug)]
struct PathData {
mtime: i64,
last_check: Instant,
}

#[derive(Debug)]
struct WatchData {
is_recursive: bool,
paths: HashMap<PathBuf, PathData>,
Expand All @@ -35,6 +38,16 @@ pub struct PollWatcher {
delay: Duration,
}

impl Debug for PollWatcher {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PollWatcher")
.field("watches", &self.watches)
.field("open", &self.open)
.field("delay", &self.delay)
.finish()
}
}

fn emit_event(event_handler: &Mutex<dyn EventHandler>, res: Result<Event>) {
if let Ok(mut guard) = event_handler.lock() {
let f: &mut dyn EventHandler = &mut *guard;
Expand Down
1 change: 1 addition & 0 deletions src/windows.rs
Expand Up @@ -54,6 +54,7 @@ enum Action {
Configure(Config, Sender<Result<bool>>),
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum MetaEvent {
SingleWatchComplete,
WatcherAwakened,
Expand Down

0 comments on commit 704e6d6

Please sign in to comment.