-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Guide: develop the exposition of arrays, vectors, and slices. #17962
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pcwalton (or someone else) soon. |
brackets (`[]`) with `vec!`. Rust allows you to use either in either situation, | ||
this is just convention. | ||
Because arrays always have a fixed length, the length is actually part of the | ||
type: an array holding `N` items of type `T` has type `[T,..N]`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm slightly concerned about this notation here, because we have yet to use generics, so it doesn't really mean anything. It's one of the reasons I didn't write it in the original version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was mentioned:
Rust has different types to represent this idea:
Vec<T>
(a 'vector'),[T, .. N]
(an 'array'), and&[T]
(a 'slice').
I'm assuming you mean you didn't mention what T
and N
are? I wasn't thinking generics, just a pseudo-high-school-algebra point of view: these are "variables" that stand for something. I can take that bit out if you feel it's too difficult.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, just we haven't explained this notation whatsoever at this point.
Thank you! I think overall this is an improvement, I just have a few inline comments. Also, one space after a period, please. |
5fb068f
to
ec6dae0
Compare
OK, made the changes you suggested. Thanks for the guidance, and let me know if there's anything else you'd like to fix. |
Similar to `&str`, a slice is a reference to another array. We can get a | ||
slice from a vector by using the `as_slice()` method: | ||
A **vector** is a dynamic or "growable" array, implemented as the standard | ||
library type [`Vec<T>`](http://doc.rust-lang.org/std/vec/). Vectors are to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a relative link, just std/vec
.
And probably should have another brief "remember, we'll talk about what the <T>
means later" bit here too.
Just a few last nits. This is really improved overall. Thanks for the quick turnaround! Editing is the worst part of the writing process 😄 |
ec6dae0
to
9107d30
Compare
No problem, here you go. |
is `names[0]` and the second name is `names[1]`. The above example prints | ||
`The second name is: Brian`. If you try to use a subscript that is not in the | ||
array, you will get an error: array access is bounds-checked at run-time. Such | ||
errant access is the source of many a bug in other systems programming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/a bug/bugs
r=me after that last typo, thank you @parir ! |
9107d30
to
ff90d1b
Compare
Cool, thanks again for all the help, and for a great Guide. |
The array is the fundamental concept; vectors are growable arrays, and slices are views into either. Show common array ops up front: length and iteration. Mention arrays are immutable by default. Highlight definite initialization and bounds-checking as safety features. Show that you only need a type suffix on one element of initializers. Explain that vectors are a value-add library type over arrays, not a fundamental type; show they have the same "interface." Motivate slices as efficient views into arrays; explain you can slice vectors, Strings, &str because they're backed by arrays.
ff90d1b
to
1ce5a56
Compare
OK, fixed a missing type suffix; sorry about that. I can't run the doc tests because of #17220 I think. Try this. |
The array is the fundamental concept; vectors are growable arrays, and slices are views into either. Show common array ops up front: length and iteration. Mention arrays are immutable by default. Highlight definite initialization and bounds-checking as safety features. Show that you only need a type suffix on one element of initializers. Explain that vectors are a value-add library type over arrays, not a fundamental type; show they have the same "interface." Motivate slices as efficient views into arrays; explain you can slice vectors, Strings, &str because they're backed by arrays. Show off new, easy-to-read [a..b] slice syntax.
fix: Fix Return Type Syntax to include `..` (i.e. `method(..)` and not `method()`) as specified in the RFC Fixes rust-lang#17952.
The array is the fundamental concept; vectors are growable arrays, and
slices are views into either. Show common array ops up front: length
and iteration. Mention arrays are immutable by default. Highlight
definite initialization and bounds-checking as safety features. Show
that you only need a type suffix on one element of initializers.
Explain that vectors are a value-add library type over arrays, not a
fundamental type; show they have the same "interface." Motivate slices
as efficient views into arrays; explain you can slice vectors, Strings,
&str because they're backed by arrays. Show off new, easy-to-read
[a..b] slice syntax.