Skip to content
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

Move HashMap to alloc::collections #56192

Closed
WildCryptoFox opened this issue Nov 24, 2018 · 8 comments
Closed

Move HashMap to alloc::collections #56192

WildCryptoFox opened this issue Nov 24, 2018 · 8 comments
Labels
A-allocators Area: Custom and system allocators A-collections Area: `std::collection` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@WildCryptoFox
Copy link
Contributor

WildCryptoFox commented Nov 24, 2018

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 { .. }
}
@sfackler
Copy link
Member

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

@WildCryptoFox
Copy link
Contributor Author

WildCryptoFox commented Nov 24, 2018

@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.

@jethrogb
Copy link
Contributor

This is rust-lang-nursery/portability-wg#11

@jonas-schievink jonas-schievink added A-allocators Area: Custom and system allocators A-collections Area: `std::collection` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jan 27, 2019
@steveklabnik
Copy link
Member

Triage: not aware of any real movement here.

@Amanieu
Copy link
Member

Amanieu commented Jan 22, 2020

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?

@jethrogb
Copy link
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.

@jethrogb
Copy link
Contributor

Dup of #27242?

@dtolnay
Copy link
Member

dtolnay commented May 27, 2020

Closing in favor of #27242.

@dtolnay dtolnay closed this as completed May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-allocators Area: Custom and system allocators A-collections Area: `std::collection` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants