diff --git a/src/type_aliases.rs b/src/type_aliases.rs index 423071c9..67ca4210 100644 --- a/src/type_aliases.rs +++ b/src/type_aliases.rs @@ -20,14 +20,16 @@ pub type SelectedDependencies = Map; /// while the latter means they could not be fetched by the [DependencyProvider](crate::solver::DependencyProvider). pub type DependencyConstraints = Map; +pub type Map = MapI>; + #[derive(Debug, Clone)] -pub struct Map> { +pub struct MapI { map: std::collections::HashMap, } -impl Map { - pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Map { - Map { +impl MapI { + pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> MapI { + MapI { map: std::collections::HashMap::with_capacity_and_hasher(capacity, hasher), } } @@ -57,7 +59,7 @@ impl Map { } } -impl Map { +impl MapI { pub fn insert(&mut self, k: K, v: V) -> Option { self.map.insert(k, v) } @@ -87,28 +89,50 @@ impl Map { } } -impl Default for Map { - fn default() -> Map { - Map { +#[cfg(feature = "serde")] +impl serde::Serialize for MapI { + fn serialize(&self, s: SE) -> Result { + self.map.serialize(s) + } +} + +#[cfg(feature = "serde")] +impl< + 'de, + K: Hash + Eq + serde::Deserialize<'de>, + V: serde::Deserialize<'de>, + S: Default + BuildHasher, + > serde::Deserialize<'de> for MapI +{ + fn deserialize>(de: D) -> Result { + Ok(MapI { + map: std::collections::HashMap::deserialize(de)?, + }) + } +} + +impl Default for MapI { + fn default() -> MapI { + MapI { map: std::collections::HashMap::default(), } } } -impl PartialEq for Map { - fn eq(&self, other: &Map) -> bool { +impl PartialEq for MapI { + fn eq(&self, other: &MapI) -> bool { self.map.eq(&other.map) } } -impl Extend<(K, V)> for Map { +impl Extend<(K, V)> for MapI { fn extend>(&mut self, it: T) { self.map.extend(it) } } impl<'a, K: 'a + Hash + Eq + Clone, V: 'a + Clone, S: BuildHasher> Extend<(&'a K, &'a V)> - for Map + for MapI { fn extend>(&mut self, it: T) { self.map @@ -116,16 +140,16 @@ impl<'a, K: 'a + Hash + Eq + Clone, V: 'a + Clone, S: BuildHasher> Extend<(&'a K } } -impl FromIterator<(K, V)> for Map { - fn from_iter>(it: I) -> Map { - Map { +impl FromIterator<(K, V)> for MapI { + fn from_iter>(it: I) -> MapI { + MapI { map: FromIterator::from_iter(it), } } } impl, Q: Eq + Hash + ?Sized, V, S: BuildHasher> std::ops::Index<&Q> - for Map + for MapI { type Output = V; @@ -134,7 +158,7 @@ impl, Q: Eq + Hash + ?Sized, V, S: BuildHasher> std::op } } -impl IntoIterator for Map { +impl IntoIterator for MapI { type Item = (K, V); type IntoIter = MapIntoIter; @@ -147,7 +171,7 @@ impl IntoIterator for Map { } } -impl<'a, K: Eq + Hash, V, S: BuildHasher> IntoIterator for &'a Map { +impl<'a, K: Eq + Hash, V, S: BuildHasher> IntoIterator for &'a MapI { type Item = (&'a K, &'a V); type IntoIter = MapIter<'a, K, V, S>; @@ -157,7 +181,7 @@ impl<'a, K: Eq + Hash, V, S: BuildHasher> IntoIterator for &'a Map { } pub struct MapIter<'a, K, V, S = BuildHasherDefault> { - map: &'a Map, + map: &'a MapI, order: std::vec::IntoIter<&'a K>, } @@ -171,7 +195,7 @@ impl<'a, K: Eq + Hash, V, S: BuildHasher> Iterator for MapIter<'a, K, V, S> { } pub struct MapIntoIter> { - map: Map, + map: MapI, order: std::vec::IntoIter, }