Skip to content

docs: Vectors are to slices what String is to &str #24079

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
wants to merge 1 commit into from
Closed

docs: Vectors are to slices what String is to &str #24079

wants to merge 1 commit into from

Conversation

nhowell
Copy link
Contributor

@nhowell nhowell commented Apr 4, 2015

This just doesn't sound right to me. I believe it's meant to say "arrays" instead of "slices". Slices aren't even mentioned until later in the page.

Please let me know if I'm just misunderstanding. Thanks

I believe it's meant to say "arrays" instead of "slices". Slices aren't even mentioned until later in the page.
@rust-highfive
Copy link
Contributor

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@steveklabnik
Copy link
Member

This is incorrect. Arrays own their data. &strs, like slices, do not.

@nhowell
Copy link
Contributor Author

nhowell commented Apr 4, 2015

@steveklabnik I think this sentence needs reworded or explained then. I took it to refer to the growable aspect of Vectors compared to arrays, like Strings are to &str, and not about data ownership.

@steveklabnik steveklabnik reopened this Apr 4, 2015
@steveklabnik
Copy link
Member

Let's shop it in this PR then. Do you have a suggestion?

@nhowell
Copy link
Contributor Author

nhowell commented Apr 4, 2015

Yeah, let me think it over and update this later (on mobile right now). Thanks.

@nhowell nhowell changed the title docs: Vectors are to arrays what String is to &str docs: Vectors are to slices what String is to &str Apr 6, 2015
@nhowell
Copy link
Contributor Author

nhowell commented Apr 6, 2015

@steveklabnik What if we remove the sentence from this paragraph:

A vector is a dynamic or "growable" array, implemented as the standard
library type Vec<T> (we'll talk about what the <T> means
later). Vectors always allocate their data on the heap. Vectors are to slices
what String is to &str.
You can create them with the vec! macro:

and incorporate it into this one?

A slice is a reference to (or "view" into) an array. They are useful for
allowing safe, efficient access to a portion of an array without copying.
In this way, slices are to arrays what &str is to String. For example, you
might want to reference just one line of a file read into memory.
By nature, a slice is not created directly, but from an existing variable.
Slices have a length, can be mutable or not, and in many ways behave like
arrays:

Also, let me know if that's incorrect in any way.

@steveklabnik
Copy link
Member

I like it. I would still say "vector" and not "array" in the revision: A String is a wrapper around Vec<u8>, just like str is a wrapper around [u8]. But seems good!

@bors
Copy link
Collaborator

bors commented Apr 8, 2015

☔ The latest upstream changes (presumably #24195) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton
Copy link
Member

r? @steveklabnik

(reassigning)

@steveklabnik
Copy link
Member

@nhowell are you interested in keeping up with this PR?

@nhowell
Copy link
Contributor Author

nhowell commented Apr 17, 2015

Yeah, I still would like to change this, and especially with the new TOC, it just doesn't seem to belong there. But I haven't thought of the best way to word it/move it to yet. Saying vector instead of array there just doesn't fit with the paragraph... I'll have something this weekend.

@steveklabnik
Copy link
Member

Okay 👍

@nhowell
Copy link
Contributor Author

nhowell commented Apr 21, 2015

I was just looking over the book again before doing anything with this PR and noticed that you've updated the way you present it. I quite like it now, so, I'll go ahead and close this PR.

Thanks!

@nhowell nhowell closed this Apr 21, 2015
@nhowell nhowell deleted the patch-1 branch April 21, 2015 01:32
@steveklabnik
Copy link
Member

Ah yes! This PR did impact doing that though, so 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 this pull request may close these issues.

5 participants