-
Notifications
You must be signed in to change notification settings - Fork 64
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
Stream-based API is difficult to use due to buffer lifetime #120
Comments
I don't think I'll have time to work on this very soon. I'll take a look eventually, but in the meantime, any help is appreciated. |
This example shows how to use inotify's stream as future polled by tokio's event loop which is cheap in computational terms using Rust idioms. It also shows how to workaround issue hannobraun#120 hannobraun#120
I have a potential solution for this, but it'll require another API change. Happy to open a PR if you're interested. |
Thank you, I'm always interested in fixing problems. Breaking compatibility is a downside, of course, but I think it's unreasonable to rule that out while the API is having problems like this. |
This commit changes the `EventStream` type to hopefully avoid some of the previously observed difficulties (viz. hannobraun#120) around the lifetime of the user-provided buffer. Previously, calls to `EventStream::new` were required to provide an `&'a mut [u8]`, where the `EventStream` is generic over the lifetime `'a`. This is an issue in many cases, where the `EventStream` must live for the `'static` lifetime, as it requires a `'static mut` buffer, which is difficult to create safely. This branch changes the `EventStream` type to be generic over a type `T` which implements `AsRef<[u8]>` and `AsMut<[u8]>`. Since an `&mut [u8]` implements these traits, means that the `EventStream` may now be constructed with an owned buffer _or_ a borrowed buffer. Thus, users can pass in a `&mut [u8]` to a short-lived `EventStream`, while a `'static` one can be constructed by passing in a `[u8; N]`, a `Vec<u8>`, _or_ a `&'static mut [u8]`. Additionally, this means that buffer types from other crates (such as `bytes`) could theoretically be used, without requiring `inotify` to depend on those crates. I'm not sure if this would actually happen that often in practice, but it's a nice side benefit. Fixes hannobraun#120. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
This commit changes the `EventStream` type to hopefully avoid some of the previously observed difficulties (viz. hannobraun#120) around the lifetime of the user-provided buffer. Previously, calls to `EventStream::new` were required to provide an `&'a mut [u8]`, where the `EventStream` is generic over the lifetime `'a`. This is an issue in many cases, where the `EventStream` must live for the `'static` lifetime, as it requires a `'static mut` buffer, which is difficult to create safely. This branch changes the `EventStream` type to be generic over a type `T` which implements `AsRef<[u8]>` and `AsMut<[u8]>`. Since an `&mut [u8]` implements these traits, means that the `EventStream` may now be constructed with an owned buffer _or_ a borrowed buffer. Thus, users can pass in a `&mut [u8]` to a short-lived `EventStream`, while a `'static` one can be constructed by passing in a `[u8; N]`, a `Vec<u8>`, _or_ a `&'static mut [u8]`. Additionally, this means that buffer types from other crates (such as `bytes`) could theoretically be used, without requiring `inotify` to depend on those crates. I'm not sure if this would actually happen that often in practice, but it's a nice side benefit. Fixes hannobraun#120. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@hannobraun I've opened #124 to resolve this issue --- please let me know what you think! It works quite well in my use-case but do let me know if I've overlooked something. |
Remove example that works around issue #120
See #106 (comment).
#119 adds an example for working around this issue.
The text was updated successfully, but these errors were encountered: