]> git.lizzy.rs Git - rust.git/commit
rollup merge of #19512: cybergeek94/master
authorCorey Richardson <corey@octayn.net>
Fri, 5 Dec 2014 18:07:41 +0000 (10:07 -0800)
committerCorey Richardson <corey@octayn.net>
Fri, 5 Dec 2014 18:07:41 +0000 (10:07 -0800)
commit33e96be29919be817d78eb932b58c237ac507ea6
tree4e8a8b9381cc230816cf778fd3eb1d947668e661
parenta8c1812f365c3b7466536f57d4eb745a90ca31e9
parent2e1911b47ae5a4fd8cf4c4a98e739666f99daf82
rollup merge of #19512: cybergeek94/master

Added the example from [this Reddit thread][1], reworked to be more robust with correct logic (first link skipped the 0th and 1st Fibonacci numbers, second forgot about the last two valid values before overflow). Will yield all Fibonacci numbers sequentially in the range `[0, <u32 as Int>::max_value())`.

If the example is too complicated I can change it to a more naive version, perhaps using signed integers to check for overflow instead of `Option` and `.checked_add()`.

Also reworded the doc comments to clarify the usage and behavior of `Unfold`, as the thread suggested that it wasn't really clear how `Unfold` worked and when one should use it.

This change is in the `core` crate but I based the example on `std` since that's where most readers will find the example. I included a note about `core` for clarity. Edit: removed.

Tested with `rustdoc src/libcore/lib.rs`. Rebased against latest master as of the creation of this PR.

[1]: http://www.reddit.com/r/rust/comments/2ny8r1/a_question_about_loops/cmighu4?context=10000
src/libcore/iter.rs