Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core::iter::Unfold: reword docs and add example #19512

Merged
merged 1 commit into from
Dec 5, 2014
Merged

core::iter::Unfold: reword docs and add example #19512

merged 1 commit into from
Dec 5, 2014

Conversation

abonander
Copy link
Contributor

Added the example from this Reddit thread, 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.

@alexcrichton
Copy link
Member

r? @steveklabnik

/// An iterator that yields sequential Fibonacci numbers, and stops on overflow.
///
/// ```rust
/// // Both imports available in the `core` crate as well
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to say this, as a ton of stuff is just reexported from core. The current approach is to just treat all inline docs as though they're just in std.

@steveklabnik
Copy link
Member

I think the complexity is fine. r=me after removing the comment about core

@abonander
Copy link
Contributor Author

@steveklabnik Done!

@steveklabnik
Copy link
Member

Sorry, can you squash these two real quick?

@abonander
Copy link
Contributor Author

Squashed.

@steveklabnik
Copy link
Member

❤️

@abonander
Copy link
Contributor Author

Looks like this is getting rolled up in #19508.

@alexcrichton alexcrichton merged commit 2e1911b into rust-lang:master Dec 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants