Skip to content

Clarify in the book that indexing into a vector must be done with a usize #28693

Closed
@bstrie

Description

@bstrie

Someone came into the channel today confused at how to index into a vector. Their problem was that the variable that they wanted to use as an index was an i8. Casting actually crossed their mind, but they gave up after trying v[foo as i32] and v[foo as isize]. The page at http://doc.rust-lang.org/stable/book/vectors.html could stand to have a sentence mentioning how to index with a variable (currently it just indexes with constants, which all properly get inferred to usize without the reader realizing).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions