3 ms·
For clarity it is called try_for_each: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#method.try_for_each https://doc.rust-lang.org/stable/std/it
by cormacrelf 4y ago
For clarity it is called try_for_each: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#method.try_for_each https://doc.rust-lang.org/stable/std/iter/trait.Iterator.htm...
The ? operator can be used both inside and after it like so:
iter.try_for_each(|_| { … xxx?; … })?;
- vlovich123 4y agoThe author is right that this doesn’t compose though. What happens when the closure is async? Do we need an tier.async_for_each? What if we want both? Does the library author need to provide a try_async_for_each? This is a combinatorial explosion for each additional effect added which means it’s not composable. https://blog.rust-lang.org/inside-rust/2022/07/27/keyword-generics.html https://blog.rust-lang.org/inside-rust/2022/07/27/keyword-ge...
- dpbriggs 4y agoOh neat, I didn't know that existed. That's a combination of what I was trying to say above. If your for loop body is infallible then for_each is good enough. If you're trying to 'collect' some iterator into some data structure T, you can collect into Result<T, _> and question mark on that.