Skip to content

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

Open
@Rjected

Description

@Rjected

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:

// The `HashMap` implementation.
// Use `hashbrown` if requested with "map-hashbrown" or required by `no_std`.
cfg_if! {
if #[cfg(any(feature = "map-hashbrown", not(feature = "std")))] {
use hashbrown as imp;
} else {
use hashbrown as _;
use std::collections as imp;
}
}
#[doc(no_inline)]
pub use imp::{hash_map, hash_map::Entry, hash_set};

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

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions