File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -380,9 +380,37 @@ macro_rules! dbg {
380
380
} ;
381
381
}
382
382
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.
384
410
///
385
411
/// [`HashMap`]: crate::collections::HashMap
412
+ /// [`HashMap::new`]: crate::collections::HashMap::new
413
+ /// [`HashMap::insert`]: crate::collections::HashMap::insert
386
414
#[ macro_export]
387
415
#[ allow_internal_unstable( hint_must_use) ]
388
416
#[ rustc_diagnostic_item = "hash_map_macro" ]
You can’t perform that action at this time.
0 commit comments