pub fn deserialize<'de, D, T, K, V>(deserializer: D) -> Result<T, D::Error>
    where
        T: PreventDuplicateInsertsMap<K, V>,
        K: Deserialize<'de>,
        V: Deserialize<'de>,
        D: Deserializer<'de>,
    {
        struct MapVisitor<T, K, V> {
            marker: PhantomData<T>,
            map_key_type: PhantomData<K>,
            map_value_type: PhantomData<V>,
        }

        impl<'de, T, K, V> Visitor<'de> for MapVisitor<T, K, V>
        where
            T: PreventDuplicateInsertsMap<K, V>,
            K: Deserialize<'de>,
            V: Deserialize<'de>,
        {
            type Value = T;

            fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                formatter.write_str("a map")
            }

            #[inline]
            fn visit_map<A>(self, mut access: A) -> Result<Self::Value, A::Error>
            where
                A: MapAccess<'de>,
            {
                let mut values = Self::Value::new(access.size_hint());

                while let Some((key, value)) = access.next_entry()? {
                    if !values.insert(key, value) {
                        return Err(Error::custom("invalid entry: found duplicate key"));
                    };
                }

                Ok(values)
            }
        }

        let visitor = MapVisitor {
            marker: PhantomData,
            map_key_type: PhantomData,
            map_value_type: PhantomData,
        };
        deserializer.deserialize_map(visitor)
    }
/// Deserialize a map and return an error on duplicate keys
Deserialize a map and return an error on duplicate keys
Deserialize a map and return an error on duplicate keys
pub fn deserialize<'de, D, T, K, V>(deserializer: D) -> Result<T, D::Error>
    where
        T: PreventDuplicateInsertsMap<K, V>,
        K: Deserialize<'de>,
        V: Deserialize<'de>,
        D: Deserializer<'de>,
    {
        struct MapVisitor<T, K, V> {
            marker: PhantomData<T>,
            map_key_type: PhantomData<K>,
            map_value_type: PhantomData<V>,
        }
        impl<'de, T, K, V> Visitor<'de> for MapVisitor<T, K, V>
        where
            T: PreventDuplicateInsertsMap<K, V>,
            K: Deserialize<'de>,
            V: Deserialize<'de>,
        {
            type Value = T;
            fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                formatter.write_str("a map")
            }
            #[inline]
            fn visit_map<A>(self, mut access: A) -> Result<Self::Value, A::Error>
            where
                A: MapAccess<'de>,
            {
                let mut values = Self::Value::new(access.size_hint());
                while let Some((key, value)) = access.next_entry()? {
                    if !values.insert(key, value) {
                        return Err(Error::custom("invalid entry: found duplicate key"));
                    };
                }
                Ok(values)
            }
        }
        let visitor = MapVisitor {
            marker: PhantomData,
            map_key_type: PhantomData,
            map_value_type: PhantomData,
        };
        deserializer.deserialize_map(visitor)
    }
pub fn deserialize < ' de , D , T , K , V > ( deserializer : D ) -> Result < T , D :: Error > where T : PreventDuplicateInsertsMap < K , V > , K : Deserialize < ' de > , V : Deserialize < ' de > , D : Deserializer < ' de > , { struct MapVisitor < T , K , V > { marker : PhantomData < T > , map_key_type : PhantomData < K > , map_value_type : PhantomData < V > , } impl < ' de , T , K , V > Visitor < ' de > for MapVisitor < T , K , V > where T : PreventDuplicateInsertsMap < K , V > , K : Deserialize < ' de > , V : Deserialize < ' de > , { type Value = T ; fn expecting ( & self , formatter : & mut fmt :: Formatter < ' _ > ) -> fmt :: Result { formatter . write_str ( " " ) } # [ inline ] fn visit_map < A > ( self , mut access : A ) -> Result < Self :: Value , A :: Error > where A : MapAccess < ' de > , { let mut values = Self :: Value :: new ( access . size_hint ( ) ) ; while let Some ( ( key , value ) ) = access . next_entry ( ) ? { if ! values . insert ( key , value ) { return Err ( Error :: custom ( " " ) ) ; } ; } Ok ( values ) } } let visitor = MapVisitor { marker : PhantomData , map_key_type : PhantomData , map_value_type : PhantomData , } ; deserializer . deserialize_map ( visitor ) }
Deserialize a map and return an error on duplicate keys
Deserialize a map and return an error on duplicate keys
deserializer
D
deserializer
D