Skip to content

Move HashMap to alloc::collections #56192

Closed as duplicate
Closed as duplicate

Description

@WildCryptoFox

Can we move HashMap to alloc::collections?

std could use a type alias to assume the default, and use a trait to add the new and with_capacity methods back.

pub type HashMap<K, V, S = RandomState> = alloc::collections::hash_map::HashMap<K, V, S>;

pub trait HashMapExt {
  fn new() -> Self;
  fn with_capacity(n: usize) -> Self;
}

impl<K: Eq + Hash, V> HashMapExt for HashMap<K, V> {
  fn new() -> Self { .. }
  fn with_capacity(n: usize) -> Self { .. }
}

Activity

  1. sfackler commented on Nov 24, 2018

    @sfackler
    Member

    The default hasher requires access to the OS's random number generator which isn't available in liballoc.

  2. WildCryptoFox commented on Nov 24, 2018

    @WildCryptoFox
    Author

    @sfackler I realised this, thus the default would be set in std via that type alias, not in alloc. And why we need the trait to implement the new and with_capacity methods.

  3. jethrogb commented on Nov 26, 2018

    @jethrogb
    Contributor
  4. added
    A-allocatorsArea: Custom and system allocators
    A-collectionsArea: `std::collections` (prefer A-binaryheap, A-btree, A-hashtable, A-linkedlist, A-vecdeque)
    T-libs-api[DEPRECATED; DO NOT USE]
    on Jan 27, 2019
  5. steveklabnik commented on Jan 22, 2020

    @steveklabnik
    Contributor

    Triage: not aware of any real movement here.

  6. Amanieu commented on Jan 22, 2020

    @Amanieu
    Member

    My position is that if you need a no_std hashmap, you can just use the hashbrown crate directly. Maybe we could make this official and add it to the documentation?

  7. jethrogb commented on Jan 22, 2020

    @jethrogb
    Contributor

    That is not a generally-acceptable solution due to interoperability concerns. Currently, if you get a Vec returned from a no_std library, you can pass this to function accepting a Vec in a std library. Whatever solution we come up with for HashMap should be the same.

  8. jethrogb commented on Apr 24, 2020

    @jethrogb
    Contributor

    Dup of #27242?

  9. dtolnay commented on May 27, 2020

    @dtolnay
    Member

    Closing in favor of #27242.

  10. removed
    A-collectionsArea: `std::collections` (prefer A-binaryheap, A-btree, A-hashtable, A-linkedlist, A-vecdeque)
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-allocatorsArea: Custom and system allocatorsA-hashtableArea: `std::collections::{HashMap, HashSet}`T-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions