-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Document init of HashSet/HashMap from vector #36740
Changes from 5 commits
aed99c8
bd80e7b
3551008
ba84d4f
6c4616c
81c47d5
f953d25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,6 +335,20 @@ fn test_resize_policy() { | |
/// println!("{:?} has {} hp", viking, health); | ||
/// } | ||
/// ``` | ||
/// A HashMap with fixed list of elements can be initialized from an array: | ||
/// ``` | ||
/// use std::collections::HashMap; | ||
/// | ||
/// fn main() { | ||
/// let timber_resources: HashMap<&str, i32> = | ||
/// [ ("Norway", 100), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the space between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
/// ("Denmark", 50), | ||
/// ("Iceland", 10) ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
/// .iter().cloned().collect(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does into_iter work here, rather than iter.cloned()? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, I tried |
||
/// // use the values stored in map | ||
/// } | ||
/// ``` | ||
|
||
#[derive(Clone)] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub struct HashMap<K, V, S = RandomState> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,18 @@ const INITIAL_CAPACITY: usize = 32; | |
/// println!("{:?}", x); | ||
/// } | ||
/// ``` | ||
/// HashSet with fixed list of elements can be initialized from an array: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you put a newline above and below this line, please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
/// ``` | ||
/// use std::collections::HashSet; | ||
/// | ||
/// fn main() { | ||
/// let viking_names: HashSet<&str> = | ||
/// [ "Einar", "Olaf", "Harald" ].iter().cloned().collect(); | ||
/// // use the values stored in the set | ||
/// } | ||
/// ``` | ||
|
||
|
||
#[derive(Clone)] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub struct HashSet<T, S = RandomState> { | ||
|
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.
can you put a newline before and after this line please?
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.
done