Skip to content

Size hint for Chunks is wrongΒ #2610

@Darksonn

Description

@Darksonn

The size hint for chunks is computed as follows:

fn size_hint(&self) -> (usize, Option<usize>) {
    let chunk_len = if self.items.is_empty() { 0 } else { 1 };
    let (lower, upper) = self.stream.size_hint();
    let lower = lower.saturating_add(chunk_len);
    let upper = match upper {
        Some(x) => x.checked_add(chunk_len),
        None => None,
    };
    (lower, upper)
}

However, this is incorrect. The stream combines many items into one, so it should divide the size hints by the capacity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions