core icon indicating copy to clipboard operation
core copied to clipboard

[Feature] Make alloy-primitives `map::Entry` type usable in function signatures

Open Rjected opened this issue 6 months ago • 1 comments

Component

primitives

Describe the feature you would like

Right now alloy-primitives map::Entry can be one of two types, the first is the default collections entry type: https://doc.rust-lang.org/std/collections/hash_map/enum.Entry.html

Which is:

Entry<'a, K: 'a, V: 'a>

And the second is the hashbrown entry type: https://docs.rs/hashbrown/latest/hashbrown/hash_map/enum.Entry.html

Which is:

Entry<'a, K, V, S, A = [Global](https://doc.rust-lang.org/nightly/alloc/alloc/struct.Global.html)>

Note the additional S generic - this means that if I wanted to use the maps in a struct and create an API like:

use alloy_primitives::{B256, map::{B256Map, B256Set, Entry}};
struct ContainsMap {
    /// just some random private map
    field: B256Map<B256Set>
}

impl ContainsMap {
    fn map_entry(&mut self, key: B256) -> Entry<'_, B256, B256Set> {
        self.field.entry(key)
    }
}

Then I would get a compile error when the hashbrown impl is selected: https://github.com/alloy-rs/core/blob/8c7229d97317bbd4e8a39e829e76b1a716c3caad/crates/primitives/src/map/mod.rs#L37-L49

It would be nice to make sure the exported Entry type is usable in function signatures

Additional context

No response

Rjected avatar Apr 28 '25 21:04 Rjected