Skip to content

Rust Book Example Fix: Arrays, Vectors, and Slices #20914

Closed
@jatinn

Description

@jatinn

In the Arrays, Vectors, and Slices section the last example warns about the slice syntax.

let a = [0, 1, 2, 3, 4];
let middle = a.slice(1, 4);     // A slice of a: just the elements [1,2,3]

This fixes it however I am not sure as to why the & is needed?

let a = [0, 1, 2, 3, 4];
let middle = &a[1..4];     // A slice of a: just the elements [1,2,3]

I would submit a PR but I think some explanation is required and I am not the best person to be explaining this. (Just started looking into rust now that its in v1 alpha)

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