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

vec: fix documentation of vec::each #7321

Closed
wants to merge 1 commit into from
Closed

vec: fix documentation of vec::each #7321

wants to merge 1 commit into from

Conversation

artagnon
Copy link
Contributor

5ec3aba (Improve documentation for each, 2012-12-27) incorrectly
documented vec::each by providing examples of old_iter::BaseIter usage
in the context of a vector. Since d2e9912 (vec: remove BaseIter
implementation, 2013-06-21), those examples don't even work anymore.
Correct the examples.

Signed-off-by: Ramkumar Ramachandra [email protected]

@huonw
Copy link
Member

huonw commented Jun 23, 2013

Hi @artagnon, thanks for the docs! However, they should probably use the new method of iteration via external iterators (defined in std::iterator), since vec::each will be removed soon(-ish). That, is:

let v = [1,2,3,4,5];
v.iter().advance(|&i| { println(i.to_str()); true })

// ...

let v = [1,2,3];
for v.iter().advance |&i| {
    println(i.to_str());
}

(Note that the temporary v is required because of #3511.)

@artagnon
Copy link
Contributor Author

I know about .iter().advance; I was just documenting vec::each() in the patch. Anyhow, I pushed out a new version: merge if you're happy with this.

I suspected as much about vec::each(). Are you planning to introduce a trait to get [1,2,3].each to work in the future though? It works with hashmaps (because of the Map trait), and the asymmetry is very displeasing.

5ec3aba (Improve documentation for each, 2012-12-27) incorrectly
documented vec::each by providing examples of old_iter::BaseIter usage
in the context of a vector.  Since d2e9912 (vec: remove BaseIter
implementation, 2013-06-21), those examples don't even work anymore.
Since vec::each() will be removed soon, provide examples using
`.iter().advance`.

Signed-off-by: Ramkumar Ramachandra <[email protected]>
@huonw
Copy link
Member

huonw commented Jun 23, 2013

Well, the each method on the Map trait is likely to be removed.

There are plans for making for use these iterators (that is the for construction checks for the Iterator trait, and/or a yet-to-be-implemented Iterable trait), so one can write for v.iter() |i| { ... } or even for v |i| { ... } (the exact syntax may change), and even for map.iter() |(key, value)| { ... } (again, possibly without the .iter()).


In any case, I made a mistake, you are correct that this PR should use each rather than the new technique; however, it may not be merged, since bors testing time is at a premium at the moment and this function is slated for removal. (If each is looking like it will still exist for 0.7, then this should be merged.)

@artagnon
Copy link
Contributor Author

Okay, thanks for the explanation. I'm deleting the PR.

@artagnon artagnon closed this Jun 23, 2013
@artagnon artagnon deleted the vec-olditer-doc branch June 23, 2013 13:07
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 17, 2021
…xFrednet

Release doc: add explanation for updating the stable branch

r? `@xFrednet`

[Rendered](https://github.com/flip1995/rust-clippy/blob/doc-release-stable-branch/doc/release.md)

changelog: none
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.

2 participants