Skip to content

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

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

Closed
jatinn opened this issue Jan 11, 2015 · 1 comment · Fixed by #21013
Closed

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

jatinn opened this issue Jan 11, 2015 · 1 comment · Fixed by #21013

Comments

@jatinn
Copy link
Contributor

jatinn commented Jan 11, 2015

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)

steveklabnik added a commit to steveklabnik/rust that referenced this issue Jan 12, 2015
@steveklabnik
Copy link
Member

You need the & because we removed the auto borrowing. I've submitted a PR to fix, thanks!

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 a pull request may close this issue.

3 participants