rust-lang / rust-lang/rust

Tracking Issue for `hash_map!` macro

Open
#144,032 25 comments 28 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-tracking-issue S-tracking-needs-summary T-lang T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

View all comments

Feature gate: #![feature(hash_map_macro)]

This is a tracking issue for https://github.com/rust-lang/libs-team/issues/578

The hash_map! macro is like the vec! macro but for HashMaps, it aims to help create hash_maps with set keys for functions that require dynamic key value pairs such as a templating engine asking to fill the templates with a HashMap.

Public API
use std::hash_map;

fn main() {
    let map = hash_map! {
        "key" => "value",
        "key2" => "value2"
    }; // uses type inference.

    for (key, value) in map {
        println!("{key:?} => {value:?}");
    }
}
Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

  • Implementation: #144070
  • Reverted in #148049 due to #147971
  • Re-implemented in #154322
  • Final comment period (FCP)^1
  • Stabilization PR
Unresolved Questions
  • What separator should we use? the main proposition was =>, : was also proposed.
  • Should this macro allow using other hashers in it's syntax? If so, how?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin by reading the linked libs-team issue #578 and the implementation history in PRs #144070, #148049, and #154322. Review the unresolved separator and hasher questions, then check the feature lifecycle requirements; done means the final comment period and stabilization PR are complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.