-
Notifications
You must be signed in to change notification settings - Fork 5
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
Missing APIs #11
Comments
Consider converting this to a checklist. FromIterator and IntoIterator are implemented. |
Plus a bunch of tests for composite and non-composite keys. Relates to #11
Heads up @pitaj I'm currently putting work into |
After poking at the problem a bit: If you want to understand the problem, try to implement an impl OptionStorage<K, V> {
#[inline]
fn entry(&mut self, key: Option<K>) -> Entry<'_, ?, ?> {
match key {
Some(key) => {
// somehow this needs to return the same type as the other branch.
self.some.entry(key)
}
None => {
if self.none.is_some() {
// none occupied
} else {
// none vacant
}
}
}
}
} |
Yeah the entry API may be quite difficult to implement. Might require more than one
|
FWIW: I've now paused efforts to implement an I do have to say I'm a bit pessimistic of how cleanly it can be implemented with safe code. In particular the enum Entry<'a, K: 'a, V: 'a> {
Occupied(OccupiedEntry<'a, K, V>),
Vacant(VacantEntry<'a, K, V>),
} This has proven to be exceedingly hard to model due to the issues outlined above. An opaque entry-like API would work, but that would remove the ability to perform advanced entry-like operations by pattern matching over the enum. Feel free to keep experimenting though! |
Some thoughts: First of all, it's obvious that our entry API surface will not be identical to that in std, if only because we have Exposing variantsIt looks to me like using a single That implies that exposing the variants in the API won't be possible, because they wouldn't match between the different storage types. API designTherefore, it seems to me that we shouldn't bother matching the API of standard, and should try to construct something that best matches our uses. This is going to require some experimentation. UnsafeI'm going to try implementing an opaque API without unsafe and see how far I get. My intuition is that it will be very difficult to make it optimal without unsafe. Take |
Go for it! I'd also note that if |
Alright I think I have a promising start. Check it out here
Remarks: It looks like exposing As for unsafe, I think the only use of unsafe will be to implement We could also implement a totally-safe |
Just committed a prototype implementing I haven't implemented the derive macro yet, so I haven't tested anything yet, but I'm pretty happy with how it turned out. |
Very neat @pitaj! If you change the feature flag to instead be |
Alright I have a working version now complete with derive macro support. All that's missing is some documentation. Check it out and let me know what you think. It's available in the |
I'm gathering a list of missing APIs here instead of having them in multiple separate issues.
FromIterator
,IntoIterator
(impl more standard traits #9) (added in impl more standard traits #9).Map::contains_key
/Set::contains
(Useful APIs from HashMap / BTreeMap #10) (added in implMap::contains_key
#22).Map::is_empty
/Set::is_empty
(Useful APIs from HashMap / BTreeMap #10).Map::len
/Set::len
(Useful APIs from HashMap / BTreeMap #10).Map::retain
/Set::retain
(Useful APIs from HashMap / BTreeMap #10) (added in implMap::retain
andSet::retain
#27).Entry
api (Entry api #5) (added in Entry API #31).Thanks to @msdrigg and @pitaj for the requests!
If you see something you'd like to implement, set up a PR and poke this issue
(relates #11)
.The text was updated successfully, but these errors were encountered: