Skip to content

Commit 022caf7

Browse files
committed
docs: documented hash_map macro
1 parent 6f1e78e commit 022caf7

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

library/std/src/macros.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,37 @@ macro_rules! dbg {
380380
};
381381
}
382382

383-
/// Creates a [`HashMap`]
383+
/// Creates a [`HashMap`] containing the arguments.
384+
///
385+
/// This macro creates or either an empty [`HashMap`] using
386+
/// [`HashMap::new`] if there are no arguments, or generates
387+
/// a [`HashMap::insert`] call for each element.
388+
///
389+
/// This macro allows trailing commas.
390+
///
391+
/// This macro is used by concatenating comma separated sequences
392+
/// of `<key:expr> => <value:expr>`.
393+
///
394+
/// An example usage of this macro could be the following
395+
///
396+
/// ```rust
397+
/// let map = hash_map!{
398+
/// "key" => "value",
399+
/// "key1" => "value1"
400+
/// };
401+
///
402+
/// for (key, value) in map {
403+
/// println!("{key:?} => {value:?}");
404+
/// }
405+
/// ```
406+
///
407+
/// Note that since this macro only generates [`HashMap::insert`]
408+
/// calls, the move semantics for the values are the same as
409+
/// the insert method.
384410
///
385411
/// [`HashMap`]: crate::collections::HashMap
412+
/// [`HashMap::new`]: crate::collections::HashMap::new
413+
/// [`HashMap::insert`]: crate::collections::HashMap::insert
386414
#[macro_export]
387415
#[allow_internal_unstable(hint_must_use)]
388416
#[rustc_diagnostic_item = "hash_map_macro"]

0 commit comments

Comments
 (0)