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

tokio-stream: add StreamExt::map_while #4351

Merged
merged 5 commits into from
Dec 31, 2021

Commits on Dec 30, 2021

  1. tokio-stream: add StreamExt::map_while`

    Fixes tokio-rs#4337
    
    Rust 1.57 stabilized the `Iterator::map_while` API. This PR adds the
    same functionality to the `StreamExt` trait, to keep parity.
    BraulioVM committed Dec 30, 2021
    Configuration menu
    Copy the full SHA
    5579e9c View commit details
    Browse the repository at this point in the history
  2. bundle the boolean in an Option with the stream

    This way we can take leverage the Option optimization where for non-null
    types we don't need any extra space to represent the `None`-ness.
    Whether this applies will depend on the specific `St` type, but it's
    very common.
    BraulioVM committed Dec 30, 2021
    Configuration menu
    Copy the full SHA
    cd834df View commit details
    Browse the repository at this point in the history
  3. turn the Option<St> into a St

    `MapWhile` doesn't need to remember whether it's done. As per the contract of the `Stream` trait:
    
    > Once a stream has finished (returned Ready(None) from poll_next), calling its poll_next method again may panic, block forever, or cause other kinds of problems; the Stream trait places no requirements on the effects of such a call.
    
    This allows us to save the space that may be needed by the boolean,
    but also lets us simplify the implementation. People can use `fuse`
    if they so need.
    BraulioVM committed Dec 30, 2021
    Configuration menu
    Copy the full SHA
    cc2aac6 View commit details
    Browse the repository at this point in the history

Commits on Dec 31, 2021

  1. Update tokio-stream/src/stream_ext.rs

    Co-authored-by: Taiki Endo <te316e89@gmail.com>
    BraulioVM and taiki-e committed Dec 31, 2021
    Configuration menu
    Copy the full SHA
    b6cb91f View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    b001b6f View commit details
    Browse the repository at this point in the history