Hello,
I'm new to Rust and I have been messing around with big chains of iterators. I have a struct which takes a generic iterator that should emit Result
s, but Result
isn't a trait so I can't just do this:
struct Foo<T> {
iter: T
}
impl<T> Foo<T>
where T: Iterator,
T::Item: Result<AnotherType, ErrType> { ... }
So is there any way to make this work or should I try another approach entirely? I also tried implementing a trait for the result type I want and using that as the bound:
trait IsMyResult {}
impl IsMyResult for Result<AnotherType, ErrType> {}
but that doesn't work without writing delegating methods of Result in the trait, which is quite annoying.
Another approach I considered was using Iterator::map
, passing in a function that does a step of the computation and then putting another map after that and so on, without using structs that own the iterator “behind” themselves in the chain, but I'm not sure if this is the correct way to do things; I would appreciate some pointers.
Thank you