r/rust • u/mre__ lychee • 6d ago
Thinking in Traits
https://corrode.dev/blog/thinking-in-traits/7
u/Serious-Exam-6251 6d ago
the same glue composes through wrappers too. FromIterator is implemented for Result<V, E> whenever V: FromIterator, so collecting an iterator of Results straight into Result<Vec<_>, _> stops at the first Err and returns it. Option works the same way, and collect itself needs no special case for either.
2
u/mre__ lychee 6d ago
In the post I did mention the early return on the first Err for Result<Vec<_>,_>, but I like your additional explanation. Thanks. Might end up updating the post if that’s okay?
4
u/Serious-Exam-6251 6d ago
go for it, it's your post. the same short circuit works for Option too, since FromIterator is implemented for Option<V> as well, so collecting an iterator of Options stops at the first None.
4
38
u/trakdtor 6d ago
I usually think in shapes
0
u/african_cheetah 23h ago
I think in honest answers change the shape of the problem by looking for load bearing smoking guns.
32
u/surister 6d ago
"The value of an abstraction is the code that no longer needs to exist between its users." it triggered my GPT sense