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

bevy::utils::HashMap API is a bit unexpected compared to std::collections::HashMap #2823

Closed
pcone opened this issue Sep 14, 2021 · 2 comments
Labels
C-Docs An addition or correction to our documentation C-Usability A simple quality-of-life change that makes Bevy easier to use D-Good-First-Issue Nice and easy! A great choice to get started with Bevy

Comments

@pcone
Copy link
Contributor

pcone commented Sep 14, 2021

Bevy version

b91541b

Operating system & version

Win10/Debian, nightly rust

What you did

I spent a while trying to initialize a bevy::utils::HashMap, expecting it to be similar to the std lib one, but there is no new function, and the signature of from takes another HashMap, instead of letting you initialize from an array of (key, value) like in std::utils. The latter is really useful for inline initialization of known data into a HashMap.

What you expected to happen

I only had the 0.5 docs to go off and those made me think ::new and ::from worked the same way here (they just link to the std::utils::HashMap docs). This probably needs some specific documentation if it's changed intentionally. I think keeping the same ::from() behaviour as std::utils should be considered too as it's rather useful when creating HashMaps from already known data.

What actually happened

N/A

Additional information

@pcone pcone added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Sep 14, 2021
@pcone pcone changed the title bevy::utils::HashMap api is a bit unexpected compared to std::collections::HashMap bevy::utils::HashMap API is a bit unexpected compared to std::collections::HashMap Sep 14, 2021
@bjorn3
Copy link
Contributor

bjorn3 commented Sep 14, 2021

You can use HashMap::default() instead of HashMap::new(). HashMap::new() is only defined for the default hasher used by libstd. HashMap::default() works for any hasher that implements Default, like the ahash hasher in this case.

@alice-i-cecile alice-i-cecile added C-Usability A simple quality-of-life change that makes Bevy easier to use C-Docs An addition or correction to our documentation D-Good-First-Issue Nice and easy! A great choice to get started with Bevy and removed S-Needs-Triage This issue needs to be labelled C-Bug An unexpected or incorrect behavior labels Sep 14, 2021
@pcone
Copy link
Contributor Author

pcone commented Sep 15, 2021

I can write docs/code examples for this if someone can drop a vague outline of what needs to be done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Docs An addition or correction to our documentation C-Usability A simple quality-of-life change that makes Bevy easier to use D-Good-First-Issue Nice and easy! A great choice to get started with Bevy
Projects
None yet
3 participants