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

fix: Allow more flexible EventStream buffers #124

Merged

Commits on Jan 25, 2019

  1. fix: Allow more flexible EventStream buffers

    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>
    hawkw committed Jan 25, 2019
    Configuration menu
    Copy the full SHA
    ea3e7a3 View commit details
    Browse the repository at this point in the history