Comments (4)
Fully agreed!
I've opened #176 and #177 to track the improvements we talked about here. Any help in implementing them is very welcome. I don't have much time to work on this crate these days, but I'm standing by to review and merge any incoming pull requests.
from inotify-rs.
One thought on this would be that the current stream API takes &mut on the Inotify and does not provide a way to add additional watches. I'm working on something where I want to recursively watch a directory, and thus need to add new watches on any newly created directories. One solution would be to allow mutably borrowing an inotify from the stream, or adding functions to add/remove watches directly.
Personally I would favor adding a method to clone an Inotify. It should be safe (in a Rust sense) and the underlying representation is already friendly to this. I understand this would permit certain undesirable uses (e.g., two streams on the same inotify would each get a subset of events).
I've tried a few ways of writing this involving multiple threads, etc, which have all been clumsy. Next I want to try using select
along with read_events
which I think should be simpler.
from inotify-rs.
Thank you for your feedback, @calmofthestorm. I'm very open to improving the situation and make your use case possible, but I think allowing users to clone Inotify
would be taking it too far. It would be very error-prone, for the reasons you mention. Adding more methods to EventStream
would certainly be acceptable. Maybe there could be a separate API, Watches
, with add
and remove
methods that can be accessed both through Inotify
and EventStream
(e.g. inotify.watches().add(...)
). Maybe it could even be possible to clone a Watches
and use it anywhere.
But does creating an EventStream
even prevent you from using the original Inotify
instance? Inotify::event_stream
takes &mut self
, but the resulting EventStream
doesn't keep that reference. That means it should already be possible to use an Inotify
and an arbitrary number of EventStream
s in parallel, which seems wrong to me.
Maybe it would be better to replace Inotify::event_stream
with an into_event_stream
method that consumes the Inotify
, and make sure EventStream
has all the methods that users need.
from inotify-rs.
Thanks, I missed that the mut reference is not saved by EventStream
(but I agree with your concern that this is wrong).
I like into_event_stream
(and ideally a way to go back as well if it's easy to implement), along with having .watches()
on both Inotify
and EventStream
. I could even see an argument to make Watches
cloneable and of separated ownership (i.e., contains its own reference to the Arc with the fd).
Then you have two separate concerns -- configuring the inotify, and consuming its events. The latter can be made unique to solve the two streams on the same fd problem.
from inotify-rs.
Related Issues (20)
- Cutting a release for #171 and #173 HOT 1
- Consider addressing buffer alignment in a more robust way HOT 2
- `Inotify::event_stream` is error-prone HOT 2
- Add separate API for adding/removing watches
- Implement ToOwned for `Event<&'a OsStr>` HOT 9
- Consider using cargo clippy in test workflows HOT 1
- Consider increasing the buffer size for the stream example HOT 2
- Using Inotify::read_events in async context HOT 3
- Is it possible to get full path from Event? HOT 3
- Update minimum supported Rust version HOT 1
- duplicate event reports HOT 9
- Async runtime agnostic. HOT 2
- Bump MSRV to at least 1.56 HOT 1
- documentation for `Inotify::watches` is broken in 0.10.1 HOT 4
- Invalid argument when trying to monitor /dev/snd HOT 2
- Update dependency `bitflags` to v2? HOT 3
- docs.rs links from inotify to inotify_sys are broken HOT 4
- Fail CI build on doc warnings
- Example in API reference is broken HOT 6
- Recursive Directory Watching HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inotify-rs.