zsiciarz / 24daysofrust

Code examples accompanying my "24 days of Rust" article series.
https://zsiciarz.github.io/24daysofrust/
MIT License
370 stars 40 forks source link

Day 2: Idiomatic num_divisors() implementation #14

Closed xmartinez closed 6 years ago

xmartinez commented 6 years ago

Provide an alternative implementation for num_divisors that:

Also, update the included line ranges in day2.md accordingly (some of them were outdated).

xmartinez commented 6 years ago

I am not 100% sure that the proposed change is actually very idiomatic (I am still learning Rust), but I find the introduction of the new methods (map, product, ok) useful for learning the Result and Iterator traits.

BTW, thanks a lot for making this docs! I am finding them very helpful while getting familiar with Rust.

xmartinez commented 6 years ago

The Travis CI failure is unrelated to this pull request. It is timing out in the day20 program when fetching an external URL (http://pokeapi.co/api/v2/pokemon/111).

xmartinez commented 6 years ago

Closed/reopened PR to trigger CI builds again.

zsiciarz commented 6 years ago

Awesome, thanks! I wrote this part before 1.0, when product() was in an unstable MultiplicativeIterator trait and hence I used fold() here. But you're absolutely right about product() being idiomatic Rust today.