Both of those are made cleaner by not using for loops.
Both of those are made cleaner by not using for loops.
If you're going to do .filter , presumably you can do a .map or something and just supply a small lambda which does what was in the body of the for loop in the example?
Alternatively you could just do the filter part using an if statement in the for loop. Either of those syntaxes would be much more straightforward than doing half of one and half of the other. It just doesn't make sense to do that and point at the result as being unergonomic.
Secondly the fact that for and for_each have different characteristics is as someone else has pointed out fundamentally just that blocks and functions are different things. ie it breaks the author's mental model because their mental model is just wrong.
The ? operator can be used both inside and after it like so:
iter.try_for_each(|_| { … xxx?; … })?;https://blog.rust-lang.org/inside-rust/2022/07/27/keyword-ge...
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.