Skip to content

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

Description

@Luro02

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
}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions