Resolve the std/hashbrown conflict situation

Big diff, but it’s mostly just whitespace changes; ignore whitespace and
it’s much smaller, though still not as tiny as it could potentially be.

Essentially, this just duplicates everything for the hashbrown variant.

It’d be possible to use generic associated types to achieve this without
the duplication, but that depends on currently-unstable features, and is
probably slightly more painful to use anyway. I’ll keep the approach in
mind for a possible version 2, but for now this is the pragmatic route.
This commit is contained in:
Chris Morgan 2022-02-22 13:50:22 +11:00
parent e04b8b4d6e
commit 40e60cefd6
5 changed files with 606 additions and 606 deletions

View file

@ -7,6 +7,15 @@ being bigger than Id earlier intended.
- Fixed the broken `Extend` implementation added in 1.0.0-beta.1. - Fixed the broken `Extend` implementation added in 1.0.0-beta.1.
- Split the hashbrown implementation into a new module, `hashbrown`:
std and hashbrown can now coexist completely peacefully,
with `anymap::Map` being powered by `std::collections::hash_map`,
and `anymap::hashbrown::Map` being powered by `hashbrown::hash_map`.
The `raw_hash_map` alias, provided in 1.0.0-beta.1 because of the ambiguity
of what backed `anymap::Map`, is removed as superfluous and useless.
`RawMap` remains, despite not being *required*, as an ergonomic improvement.
With this, were back to proper completely additive Cargo features.
# 1.0.0-beta.1 (2022-01-25) # 1.0.0-beta.1 (2022-01-25)
- Removed `anymap::any::Any` in favour of just plain `core::any::Any`, since its - Removed `anymap::any::Any` in favour of just plain `core::any::Any`, since its

View file

@ -11,6 +11,9 @@ categories = ["rust-patterns", "data-structures", "no-std"]
license = "BlueOak-1.0.0 OR MIT OR Apache-2.0" license = "BlueOak-1.0.0 OR MIT OR Apache-2.0"
include = ["/README.md", "/COPYING", "/CHANGELOG.md", "/src"] include = ["/README.md", "/COPYING", "/CHANGELOG.md", "/src"]
[package.metadata.docs.rs]
all-features = true
[features] [features]
default = ["std"] default = ["std"]
std = [] std = []

View file

@ -41,22 +41,20 @@ assert_eq!(&*data.get::<Foo>().unwrap().str, "foot");
## Cargo features/dependencies/usage ## Cargo features/dependencies/usage
Typical Cargo.toml usage: Typical Cargo.toml usage, providing `anymap::AnyMap` *et al.* backed by `std::collections::HashMap`:
```toml ```toml
[dependencies] [dependencies]
anymap = "1.0.0-beta.1" anymap = "1.0.0-beta.1"
``` ```
No-std usage, using `alloc` and the [hashbrown](https://rust-lang.github.io/hashbrown) crate instead of `std::collections::HashMap`: No-std usage, providing `anymap::hashbrown::AnyMap` *et al.* (note the different path, required because Cargo features are additive) backed by `alloc` and the [hashbrown](https://rust-lang.github.io/hashbrown) crate:
```toml ```toml
[dependencies] [dependencies]
anymap = { version = "1.0.0-beta.1", default-features = false, features = ["hashbrown"] } anymap = { version = "1.0.0-beta.1", default-features = false, features = ["hashbrown"] }
``` ```
The `std` feature is enabled by default. The `hashbrown` feature overrides it. At least one of the two must be enabled.
**On stability:** hashbrown is still pre-1.0.0 and experiencing breaking changes. Because its useful for a small fraction of users, I am retaining it, but with *different compatibility guarantees to the typical SemVer ones*. Where possible, I will just widen the range for new releases of hashbrown, but if an incompatible change occurs, I may drop support for older versions of hashbrown with a bump to the *minor* part of the anymap version number (e.g. 1.1.0, 1.2.0). Iff youre using this feature, this is cause to *consider* using a tilde requirement like `"~1.0"` (or spell it out as `>=1, <1.1`). **On stability:** hashbrown is still pre-1.0.0 and experiencing breaking changes. Because its useful for a small fraction of users, I am retaining it, but with *different compatibility guarantees to the typical SemVer ones*. Where possible, I will just widen the range for new releases of hashbrown, but if an incompatible change occurs, I may drop support for older versions of hashbrown with a bump to the *minor* part of the anymap version number (e.g. 1.1.0, 1.2.0). Iff youre using this feature, this is cause to *consider* using a tilde requirement like `"~1.0"` (or spell it out as `>=1, <1.1`).
## Unsafe code in this library ## Unsafe code in this library

1189
src/lib.rs

File diff suppressed because it is too large Load diff

5
test
View file

@ -4,11 +4,10 @@ export RUSTFLAGS="-D warnings"
export RUSTDOCFLAGS="-D warnings" export RUSTDOCFLAGS="-D warnings"
run_tests() { run_tests() {
for release in "" "--release"; do for release in "" "--release"; do
cargo $1 test $release --no-default-features # Not very useful without std or hashbrown, but hey, it works! (Doctests emit an error about needing a global allocator, but it exits zero anyway. ¯\_(ツ)_/¯)
cargo $1 test $release --no-default-features --features hashbrown cargo $1 test $release --no-default-features --features hashbrown
cargo $1 test $release --features hashbrown
# (2>/dev/null because otherwise youll keep seeing errors and double-guessing whether they were supposed to happen or whether the script failed to exit nonzero.)
! 2>/dev/null cargo $1 test $release --no-default-features || ! echo "'cargo $1 test $release --no-default-features' failed to fail (sorry, its stderr is suppressed, try it manually)"
cargo $1 test $release cargo $1 test $release
cargo $1 test $release --all-features
done done
} }