Skip to content

a boxed iterator can't use methods in the IteratorExt trait #21361

Closed
@Kroisse

Description

@Kroisse

Example

let v = vec![1, 2, 3];
let boxed = Box::new(v.iter()) as Box<Iterator<Item=i32>>;
boxed.max()  // IteratorExt::max(*boxed) also fails

This code will be failed to compile because boxed holds a trait object that is unsized, and IteratorExt requires the Sized kind so IteratorExt can only be implemented for sized types. Like IteratorExt::map(), many methods in IteratorExt consume self, so requiring a sized type is necessary.

Adding impl Iterator for Box<Iterator> (like Reader for Box<Reader>) might solve this problem, but I'm worrying about the confliction with autoderef.

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