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

Updated example code in the documentation #36746

Closed
wants to merge 1 commit into from
Closed

Updated example code in the documentation #36746

wants to merge 1 commit into from

Conversation

green-coder
Copy link

An example code was truncated to only its first line. I went to find the missing part in the source code of Rust, and now the documentation makes sense.

An example code was truncated to only its first line. I went to find the missing part in the source code of Rust, and now the documentation makes sense.
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton
Copy link
Member

r? @steveklabnik

@steveklabnik
Copy link
Member

The intention here was to show the type signature, not the implementation. Maybe we can fix it some other way to make it clear without showing the internals?

@green-coder
Copy link
Author

But if you read the text right after, it looked like the reader was expected to see that the implementation was returning the iterator directly while it was not visible before the fix.

@steveklabnik
Copy link
Member

Could we maybe instead change the above sentence to say something like "look at the type signature of this implementation"? Would that make it more clear? the body is just a distraction.

@green-coder
Copy link
Author

green-coder commented Oct 1, 2016

The text around this modification is :

//! There's one more subtle bit here: the standard library contains an
//! interesting implementation of [`IntoIterator`]:
//!
//! ```ignore
//! impl<I: Iterator> IntoIterator for I {
//!     type Item = I::Item;
//!     type IntoIter = I;
//! 
//!     fn into_iter(self) -> I {
//!         self
//!     }
//! }
//! ```
//!
//! In other words, all [`Iterator`]s implement [`IntoIterator`], by just
//! returning themselves. This means two things:
//!
//! 1. If you're writing an [`Iterator`], you can use it with a `for` loop.
//! 2. If you're creating a collection, implementing [`IntoIterator`] for it
//!    will allow your collection to be used with the `for` loop.
//!

In my humble uninformed reader's experience (because I read it as a beginner learning Rust), it makes sense to show the implementation (the function returning self) more than to show the types above.

I suggest to simplify the example by replacing the lines:

//!     type Item = I::Item;
//!     type IntoIter = I;

by //! // [...].

@steveklabnik
Copy link
Member

I really do not want to write out the implementation here, sorry. I know that it may aid your understanding, but I don't want to expose internals like this, as a general rule. The source is still there to look at, in the end.

Thank you for the PR, but I don't think I can accept it.

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.

None yet

4 participants