A note about the design of itertools crate


This issue is about moving some Clippy lints into Rustc where they probably belong (but I suspect this issue will need to be split into several issues):

Similarly, I’d like in the stdlib some of the handy things currently in the Itertools crate (but there are some backwards compatibility problems in doing this, see what happened to the flatten() method):


But to me some of the things of itertools have a design problem that the Rust stdlib doesn’t have. (And I discuss this here instead of the Github page of itertools because I think some itertools things should be moved into the rust stdlib). An example of this problem is visible in the zip_longest method:


It’s similar to the function with the same name in the Python stdlib:


(Note: the API of Python zip_longest has a problem, so here I am not saying that it’s better than the Rust version).

The Rust method yields EitherOrBoth structs:


In my opinion zip_longest is a useful method, but I think a standard library should reduce the infrastructure, reduce the number of things (and data structures) to remember. I understand that EitherOrBoth makes the API types of zip_longest more precise, but they add things to remember or to look into the documentation. So I think I’d like Rust zip_longest to return something that doesn’t need to define a new type like EitherOrBoth, something like:

(Option<T>, Option<T>)

In the Rust Itertools there are other similar examples of specialized return types that I think are similarly a problem, I think library functions should use standard types as much as possible:



Since you mentioned this type, how would you solve the reason this exists? Are you saying you just wouldn’t support non-Clone types in .min_max()?

(Now that enum layout is a thing, maybe it would be better as Option<Something<T>>, but there’s still a good reason for an enum here.)