Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Debug impl to fs/windows watchers #378

Merged
merged 1 commit into from Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -397,6 +397,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