-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Allow more flexible EventStream buffers
This commit changes the `EventStream` type to hopefully avoid some of the previously observed difficulties (viz. #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 #120. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
- Loading branch information
Showing
4 changed files
with
24 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters