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

Chunks misbehaves for zero-sized item types #1475

Closed
benw opened this issue Mar 12, 2019 · 2 comments · Fixed by #1483
Closed

Chunks misbehaves for zero-sized item types #1475

benw opened this issue Mar 12, 2019 · 2 comments · Fixed by #1483

Comments

@benw
Copy link

benw commented Mar 12, 2019

Calling .chunks(n) on a stream of zero-sized items produces a stream that waits until the original stream terminates, and then yields all the items at once, regardless of the value of n.

use futures::stream::{self, Stream};

fn main() {
    let val = ();
    for i in stream::repeat::<_, ()>(val).take(5).chunks(3).wait() {
        dbg!(i).ok();
    }
}

Actual output:

[src/main.rs:6] i = Ok(
    [
        (),
        (),
        (),
        (),
        ()
    ]
)

Expected output:

[src/main.rs:6] i = Ok(
    [
        (),
        (),
        ()
    ]
)
[src/main.rs:6] i = Ok(
    [
        (),
        ()
    ]
)

Chunks should probably hold its own cap: usize field rather than relying on items.capacity(), because Vec::<()> reports capacity of usize::MAX regardless of what capacity was requested.

@Nemo157
Copy link
Member

Nemo157 commented Mar 12, 2019

0.3 has the same misbehaviour, tested with:

#![feature(async_await, await_macro, futures_api)]

use futures::stream::{self, StreamExt};

fn main() {
    futures::executor::block_on(async {
        let mut stream = stream::repeat(()).take(5).chunks(3);
        while let Some(i) = await!(stream.next()) {
            dbg!(i);
        }
    });
}

@cramertj
Copy link
Member

seems like a bug in Vec, IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants