-
Notifications
You must be signed in to change notification settings - Fork 161
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
Unify std and no_std APIs for IndexMap
and IndexSet
#207
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ pub use crate::rayon::set as rayon; | |
|
||
#[cfg(has_std)] | ||
use std::collections::hash_map::RandomState; | ||
#[cfg(not(has_std))] | ||
use hashbrown::hash_map::DefaultHashBuilder; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As @cuviper said, we can't expose hashbrown types in our public API. This change would make hashbrown a public dependency and it would not be possible for us to bump that version without changing our own major version. As cuviper said, we could just solve that with a wrapper. Hashbrown is not becoming our public dependency, because it causes problems for our own versioning story. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, thanks for the clarification. |
||
|
||
use crate::vec::{self, Vec}; | ||
use core::cmp::Ordering; | ||
|
@@ -64,7 +66,7 @@ pub struct IndexSet<T, S = RandomState> { | |
map: IndexMap<T, (), S>, | ||
} | ||
#[cfg(not(has_std))] | ||
pub struct IndexSet<T, S> { | ||
pub struct IndexSet<T, S = DefaultHashBuilder> { | ||
map: IndexMap<T, (), S>, | ||
} | ||
|
||
|
@@ -124,7 +126,6 @@ where | |
} | ||
} | ||
|
||
#[cfg(has_std)] | ||
impl<T> IndexSet<T> { | ||
/// Create a new set. (Does not allocate.) | ||
pub fn new() -> Self { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahash pulls in a non-trivial amount of dependencies. On linux it pulls in libc, version_check, cfg-if, once_cell and getrandom.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find, I hadn't noticed that since I primarily build for a custom
no_std
target. If you're aware of other hashing crates with fewer dependencies, I could experiment with using them as the default. I'll look for others myself too, in the meantime.If considering multiple hashing crates, we could gate the inclusion of each one behind a feature; this would allow
std
andno_std
users alike to select different default hashers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can only do that if we make the features mutually exclusive, as a hard build error. You could have one part of a large dependency tree that wants
indexmap
one way, and another part wanting the other way, but Cargo unifies dependencies into one build so we can't satisfy both.But that's only about default
S
and the few methods that assume that. Most of the API is perfectly fine with bring-your-own-hasherS
, so each part of that dependency tree can fill their own needs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I had used that approach of pseudo-mutually-exclusive features for another project via the
compile_error!()
macro, but it's admittedly tedious and feels hacky.I do hear what you're saying about multiple downstream crates using
indexmap
differently, and unfortunately there's no way around that.