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

Associated function new is not defined for any hasher on HashMap #65404

Closed
Alphare opened this issue Oct 14, 2019 · 1 comment
Closed

Associated function new is not defined for any hasher on HashMap #65404

Alphare opened this issue Oct 14, 2019 · 1 comment

Comments

@Alphare
Copy link

Alphare commented Oct 14, 2019

HashMap with a custom hasher does not implement new(). Example, with the following type alias:

type FastHashMap<K, V> = HashMap<K, V, MyFastHasher>;

let h = HashMap::new();  // Works
let f = FastHashMap::new();  // No associated function, etc.

Is there a good reason why that should happen? I've resorted to using default() since it does the same thing AFAIK, but this seems like an unnecessary restriction.

@sfackler
Copy link
Member

This is intentional, because associated type defaults don't factor into type inference: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=94783a2a4108c8f70df5fc047bba2edf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants