I want to contribute a new type and Iterator impl to an existing, published library. The iterator does io and is fallible.
I have implemented Iterator for MyType with
type Item = std::io::Result<Vec<u8>>.
However, I don’t think
Iterator<Item=Result<..>> is a good pattern. Too many things can go wrong, such as accidentally counting Errs as Oks, and so forth. For these reasons, in my own code I prefer to use fallible-iterator for iterators that can fail.
But this code is a contribution to another project which only judiciously adds new crate dependencies.
I think the Rust way of handling this is conditional compilation or “features”. What I think I’d like to do is implement
IntoFallibleIterator for MyType if the fallible-iterator crate is already a dep of the consuming crate, or if they’ve opted in to the fallible-iterator feature. That way we can get the best of both worlds. Is there a way to do it so that they automatically get FallibleIterator if they already have fallible-iterator in their project, without requiring that they opt-in to the feature in Cargo.toml?
Or do you think this is a waste of time and I should just content myself with implementing Iterator?