Skip to content

Commit

Permalink
Add Debug impl to fs/windows watchers
Browse files Browse the repository at this point in the history
Additional Debug derives are required in order to implement Debug for
`FsEventWatcher` and `ReadDirectoryChangesWatcher`.

Also, print `PollWatcher` `.event_handler` field as a pointer.
  • Loading branch information
tmfink authored and 0xpr03 committed Jan 9, 2022
1 parent 8948dd1 commit 0faae41
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/event.rs
Expand Up @@ -346,14 +346,14 @@ pub struct Event {
}

/// Additional attributes of the event.
#[derive(Clone, Default)]
#[derive(Clone, Default, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct EventAttributes {
#[cfg_attr(feature = "serde", serde(flatten))]
inner: Option<Box<EventAttributesInner>>,
}

#[derive(Clone, Default)]
#[derive(Clone, Default, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
struct EventAttributesInner {
/// Tracking ID for events that are related.
Expand Down
15 changes: 15 additions & 0 deletions src/fsevent.rs
Expand Up @@ -21,6 +21,7 @@ use fsevent_sys as fs;
use fsevent_sys::core_foundation as cf;
use std::collections::HashMap;
use std::ffi::CStr;
use std::fmt;
use std::os::raw;
use std::path::{Path, PathBuf};
use std::ptr;
Expand Down Expand Up @@ -68,6 +69,20 @@ pub struct FsEventWatcher {
recursive_info: HashMap<PathBuf, bool>,
}

impl fmt::Debug for FsEventWatcher {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("FsEventWatcher")
.field("paths", &self.paths)
.field("since_when", &self.since_when)
.field("latency", &self.latency)
.field("flags", &self.flags)
.field("event_handler", &Arc::as_ptr(&self.event_handler))
.field("runloop", &self.runloop)
.field("recursive_info", &self.recursive_info)
.finish()
}
}

// CFMutableArrayRef is a type alias to *mut libc::c_void, so FsEventWatcher is not Send/Sync
// automatically. It's Send because the pointer is not used in other threads.
unsafe impl Send for FsEventWatcher {}
Expand Down
1 change: 1 addition & 0 deletions src/poll.rs
Expand Up @@ -41,6 +41,7 @@ pub struct PollWatcher {
impl Debug for PollWatcher {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PollWatcher")
.field("event_handler", &Arc::as_ptr(&self.watches))
.field("watches", &self.watches)
.field("open", &self.open)
.field("delay", &self.delay)
Expand Down
1 change: 1 addition & 0 deletions src/windows.rs
Expand Up @@ -399,6 +399,7 @@ unsafe extern "system" fn handle_event(
}

/// Watcher implementation based on ReadDirectoryChanges
#[derive(Debug)]
pub struct ReadDirectoryChangesWatcher {
tx: Sender<Action>,
cmd_rx: Receiver<Result<PathBuf>>,
Expand Down

0 comments on commit 0faae41

Please sign in to comment.