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

Make Watcher object safe #336

Merged
merged 4 commits into from Jun 10, 2021
Merged

Make Watcher object safe #336

merged 4 commits into from Jun 10, 2021

Conversation

erickt
Copy link
Contributor

@erickt erickt commented Jun 10, 2021

This changes the Watcher trait to be object safe, which allows users to
dynamically select which backend to use. This can be helpful on systems that
support multiple file watching systems that have different tradeoffs. For
example, Chromium's file watcher on OS X will use an fsevent backend
when watching recursive directories, and a kqueues backend when not.

In order to implement this, this makes a few changes to Watcher:

  • removes new_immediate constructor.
  • removes the <P: AsRef<Path>> from the watch and unwatch.

This then replaces (and renames) calls with notify::recommended_watcher()
to get similar behavior as the old constructor.

This changes the `Watcher` trait to be object safe, which allows users to
dynamically select which backend to use. This can be helpful on systems that
support multiple file watching systems that have different tradeoffs. For
example, Chromium's file watcher on OS X will use an fsevent backend
when watching recursive directories, and a kqueues backend when not.

In order to implement this, this makes a few changes to Watcher:

* removes `new_immediate` constructor.
* removes the `<P: AsRef<Path>>` from the `watch` and `unwatch`.

This then replaces (and renames) calls with `notify::recommended_watcher()`
to get similar behavior as the old constructor.
@0xpr03
Copy link
Member

0xpr03 commented Jun 10, 2021

I think<P: AsRef<Path>> was nice to leave freedom in how you want to specify your path. Any reason to remove that ? I guess we have to remove that to allow dynamic switching via non-generic interfaces.

src/windows.rs Show resolved Hide resolved
@erickt
Copy link
Contributor Author

erickt commented Jun 10, 2021

I think<P: AsRef> was nice to leave freedom in how you want to specify your path. Any reason to remove that ? I guess we have to remove that to allow dynamic switching via non-generic interfaces.

Correct, object safe traits can't have generic parameters. It's unfortunate to have to manually pass in Path::new(), but I'm guessing most callsites only specify one or two paths by hand, so it might not be that painful in practice.

Copy link
Member

@0xpr03 0xpr03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you currently seem to have syntax errors according to CI.

@erickt erickt requested a review from 0xpr03 June 10, 2021 18:03
@erickt
Copy link
Contributor Author

erickt commented Jun 10, 2021

Note that you currently seem to have syntax errors according to CI.

Should be fixed now!

@0xpr03 0xpr03 merged commit 1fac9ca into notify-rs:main Jun 10, 2021
@0xpr03
Copy link
Member

0xpr03 commented Jun 10, 2021

Thanks, this will be a good step towards a possible dynamic runtime change, which was in the never released -next branch

@0xpr03
Copy link
Member

0xpr03 commented Jun 10, 2021

Note: we may want to document and test for this, so it isn't reverted later on with a trait under the impression of usability improvements

@erickt erickt deleted the obj branch June 10, 2021 19:06
@erickt
Copy link
Contributor Author

erickt commented Jun 10, 2021

Thanks!

Note: we may want to document and test for this, so it isn't reverted later on with a trait under the impression of usability improvements

I did add a simple test for this in src/lib.rs, where I assert that the Watcher trait is object safe. So we can't accidentally remove this feature.

@0xpr03
Copy link
Member

0xpr03 commented Jun 10, 2021

Ah yeah, had to test but that's already enough to verify it. Then I'll only have to add some docs later on for a more in-depth changelog

naglis added a commit to naglis/notify that referenced this pull request Mar 13, 2024
Notion of "immediate mode" was removed in
notify-rs#336.
naglis added a commit to naglis/notify that referenced this pull request Mar 13, 2024
Notion of "immediate mode" was removed in notify-rs#336.
0xpr03 pushed a commit that referenced this pull request Mar 28, 2024
Notion of "immediate mode" was removed in #336.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants