-
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
library-level docs for collections #17802
Conversation
//! For optimal performance, collections will generally avoid *shrinking* themselves. | ||
//! If you believe that a collection will not soon contain any *more* elements, or | ||
//! just really need the memory, the `shrink_to_fit` method prompts the collection | ||
//! to *shrink* the backing array to the minimum size capable of holding its elements. |
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.
Is this emphasis needed? (There's a lot of *...*
emphasis in this text?)
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.
Haha, wow yeah. Good call.
@huon Issues addressed. |
//! ### Use the `Set` variant of any of these `Map`s when: | ||
//! * You just want to remember which keys you've seen. | ||
//! * There is no meaningful value to associate with your keys. | ||
//! * You just want a set. |
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.
"Use a set when you want a set" isn't a particularly helpful guideine
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 it's a bit borderline, but it seemed... symmetric? My general pattern here is a gradient from "descriptive for newbies" to "what experts know", where "what experts know" is generally generic types like "it's the map" or "it's the set".
Thank you, this is super great :) Are the changes to lib.rs needed? |
@steveklabnik I'm not sure what you're referring to about changes to lib.rs? |
Sorry, btree/mod.rs |
@steveklabnik Yeah the examples won't work without it. It's just something that doing this revealed wasn't done. Figured I might as well toss it in. |
@@ -15,6 +15,8 @@ pub use self::map::MoveEntries; | |||
pub use self::map::Keys; | |||
pub use self::map::Values; | |||
pub use self::map::Entry; | |||
pub use self::map::Occupied; |
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.
BTW, you can reexport multiple things at once pub use self::map::{Occupied, Vacant};
.
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.
Want me to change that? I was just following the pattern I saw elsewhere.
Doesn't show up in the |
Found a few errors or just weird statements. Also tossed in something about adapters and |
ec4de97
to
d225903
Compare
Also I just remembered that I wrote this old thing back in the day when I first started poking at collections reform. I had always intended it to be paired with something like the contents of this PR, but I believe it was decided that it didn't have a good "place" in the docs. Anyone have any ideas? |
//! # When Should You Use Which Collection? | ||
//! | ||
//! ### Use a `Vec` when: | ||
//! * You just want to store some items temporarily, to be processed or sent elsewhere later. |
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.
The first bullet, about temporary storage -- I'm curious what the justification is? I don't see how it argues for Vec
over other collections, personally.
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.
Pushing onto a Vec is surely the most efficient way to collect up a bunch of values, no? Similarly Vecs should iterate the fastest for extracting the values when you want them.
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.
OK, I see what you have in mind. I think the "temporarily" bit threw me off -- the idea here seems to be that you just have a pile of items, where you don't care about the order or any notion of key, or equality, or priority. And yes, that argues for Vec
:)
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 not super thrilled about the current wording myself. If you have any suggestions I'm all-ears. :)
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.
"You just want want an expanding sequence of items" (somewhat redundant with the next bullet, but maybe they can/should be merged)?
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 feel like "great temp storage" and "great sequence" are distinct. Particularly the fact that order is significant in only one.
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 think "temporary storage" has a clearer/more specific meaning for you than it does for me. Would be interested to see how others feel about this? (Honestly, we could probably just drop this bullet without losing much.)
@gankro Thanks for taking this on! This is great. A few scattered thoughts:
Anyway, nice work! |
|
@gankro Ok, those all seem like super-reasonable responses. Thanks! |
@aturon new commit addresses many of your concerns. Anything outstanding? |
@gankro I'm happy to land what you've got now; always room for incremental improvements later on. |
@aturon squashed |
f6044f8
to
6ff1d78
Compare
@steveklabnik @huonw I'm happy with this -- are both of you? |
I'm fine with it. |
Maybe there could be a link in the It seems fine to me other than that. |
6ff1d78
to
2e633b3
Compare
After some IRC discussion, I went with moving this to |
2e633b3
to
1d6eda3
Compare
Adds a high-level discussion of "what collection should you use for what", as well as some general discussion of correct/efficient usage of the capacity, iterator, and entry APIs. Still building docs to confirm this renders right and the examples are good, but the content can be reviewed now.
…r=Veykril fix: Surpress type mismatches in calls with mismatched arg counts These tend to get very noisy, hiding the actual problem.
Adds a high-level discussion of "what collection should you use for what", as well as some general discussion of correct/efficient usage of the capacity, iterator, and entry APIs.
Still building docs to confirm this renders right and the examples are good, but the content can be reviewed now.