![]() # Objective - Fixes #18690 - Closes [#2065](https://github.com/bevyengine/bevy-website/pull/2065) - Alternative to #18691 The changes to the Hash made in #15801 to the [BuildHasher](https://doc.rust-lang.org/std/hash/trait.BuildHasher.html) resulted in serious migration problems and downgraded UX for users of Bevy's re-exported hashmaps. Once merged, we need to go in and remove the migration guide added as part of #15801. ## Solution - Newtype `HashMap` and `HashSet` instead of type aliases - Added `Deref/Mut` to allow accessing future `hashbrown` methods without maintenance from Bevy - Added bidirectional `From` implementations to provide escape hatch for API incompatibility - Added inlinable re-exports of all methods directly to Bevy's types. This ensures `HashMap::new()` works (since the `Deref` implementation wont cover these kinds of invocations). ## Testing - CI --- ## Migration Guide - If you relied on Bevy's `HashMap` and/or `HashSet` types to be identical to `hashbrown`, consider using `From` and `Into` to convert between the `hashbrown` and Bevy types as required. - If you relied on `hashbrown/serde` or `hashbrown/rayon` features, you may need to enable `bevy_platform_support/serialize` and/or `bevy_platform_support/rayon` respectively. --- ## Notes - Did not replicate the Rayon traits, users will need to rely on the `Deref/Mut` or `From` implementations for those methods. - Did not re-expose the `unsafe` methods from `hashbrown`. In most cases users will still have access via `Deref/Mut` anyway. - I have added `inline` to all methods as they are trivial wrappings of existing methods. - I chose to make `HashMap::new` and `HashSet::new` const, which is different to `hashbrown`. We can do this because we default to a fixed-state build-hasher. Mild ergonomic win over using `HashMap::with_hasher(FixedHasher)`. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
README.md |
Bevy Platform Support
Rust is a fantastic multi-platform language with extensive support for modern targets through its standard library.
However, some items within the standard library have alternatives that are better suited for Bevy and game engines in general.
Additionally, to support embedded and other esoteric platforms, it's often necessary to shed reliance on std
, making your crate no_std
.
These needs are handled by this crate, bevy_platform_support
.
The goal of this crate is to provide alternatives and extensions to the Rust standard library which minimize friction when developing with and for Bevy across multiple platforms.
Getting Started
Like any dependency from crates.io, use cargo
to add it to your Cargo.toml
file:
cargo add bevy_platform_support
Now, instead of importing from std
you can use bevy_platform_support
for items it has alternative for.
See the documentation for what items are available, and explanations for why you may want to use them.
no_std
Support
By default, bevy_platform_support
will activate the std
feature, requiring access to the std
crate for whichever platforms you're targeting.
To use this crate on no_std
platforms, disable default features:
bevy_platform_support = { version = "x.y.z", default-features = false }
Features
std
(default)
Enables usage of the standard library. Note that where this crate has alternatives to the standard library that it considers better than what's provided, it will provide the alternative even when std
is enabled.
This is explicitly incompatible with no_std
targets.
alloc
(default)
Enables usage of the alloc
crate. Note that this feature is automatically enabled when enabling std
.
This is compatible with most no_std
targets, but not all.
critical-section
Switches to using critical-section
as a backend for synchronization.
You may need to enable this feature on platforms with little to no support for atomic operations.