Skip to content

Document that .iter() has an element type of &T #25928

Closed
@Wilfred

Description

@Wilfred

The docs for Vec::iter show the following type:

fn iter(&self) -> Iter<T>

As a result, I was puzzled that the following doesn't work:

let bar: Vec<&str> = vec!["a", "b", "c", "b"].iter().collect();

It turns out that that Iter implements an iterator with element type &T. On the Iter docs page we see type Item = &'a T but it's easy to overlook.

I think it would be worth adding a line to Vec::iter's documentation to say:

Iterator element type is &T.

This is the approach taken in itertools docs (example) and I think it helps significantly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions