-
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 1 commit
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,23 @@ fn test_resize_policy() { | |
/// println!("{:?} has {} hp", viking, health); | ||
/// } | ||
/// ``` | ||
/// A HashMap with fixed list of elements can be initialized from vector: | ||
/// ``` | ||
/// 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().map(|&x| x).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.
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. comment merged in |
||
/// // use the values store in map | ||
/// } | ||
/// ``` | ||
/// This works for Copy types, if you want to cover non-copy types then you need to replace | ||
/// the map(|&x| x) with map(|x| x.clone()) | ||
|
||
|
||
#[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,20 @@ const INITIAL_CAPACITY: usize = 32; | |
/// println!("{:?}", x); | ||
/// } | ||
/// ``` | ||
/// HashSet with fixed list of elements can be initialized from vector: | ||
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. "from an array" |
||
/// ``` | ||
/// use std::collections::HashSet; | ||
/// | ||
/// fn main() { | ||
/// let viking_names: HashSet<&str> = | ||
/// [ "Einar", "Olaf", "Harald" ].iter().map(|&x| x).collect(); | ||
/// // use the values store in the set | ||
/// } | ||
/// ``` | ||
/// This works for Copy types, if you want to cover non-copy types then you need to replace | ||
/// the map(|&x| x) with map(|x| x.clone()) | ||
|
||
|
||
#[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.
"from an array"
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.
comments have been merged in