Skip to content
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

Implement TryFrom<[(K, V); N]> for ArrayMap<K, V, M> #13

Open
Luro02 opened this issue Aug 22, 2021 · 0 comments
Open

Implement TryFrom<[(K, V); N]> for ArrayMap<K, V, M> #13

Luro02 opened this issue Aug 22, 2021 · 0 comments
Labels

Comments

@Luro02
Copy link
Owner

Luro02 commented Aug 22, 2021

ArrayMapFacade could implement this:

impl<K, V, R, B, const N: usize> TryFrom<[(K, V); N]> for ArrayMapFacade<K, V, R, B>
where
    K: Eq + Hash,
    R: RawTable<(K, V)> + Default,
    B: BuildHasher + Default,
{
    type Error = CapacityError;

    fn try_from(value: [(K, V); N]) -> Result<Self, Self::Error> {
        let mut result = Self::with_build_hasher(B::default());

        for (key, value) in value {
            result.insert(key, value)?;
        }

        Ok(result)
    }
}

but it conflicts with the "specialized" implementation for FixedSizeTables:

array-map/src/array_map.rs

Lines 1064 to 1081 in 4390c72

impl<K, V, R, B, const N: usize> From<[(K, V); N]> for ArrayMapFacade<K, V, R, B>
where
K: Eq + Hash,
R: FixedSizeTable<(K, V), N> + Default,
B: BuildHasher + Default,
{
fn from(value: [(K, V); N]) -> Self {
let mut result = Self::with_build_hasher(B::default());
for (key, value) in value {
if let Err(error) = result.insert(key, value) {
unreachable_unchecked!(error);
}
}
result
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant