1- use std :: { collections :: HashMap , convert :: TryFrom } ;
2-
1+ use super :: super :: ZendHashTable ;
2+ use crate :: types :: ArrayKey ;
33use crate :: {
44 boxed:: ZBox ,
55 convert:: { FromZval , IntoZval } ,
66 error:: { Error , Result } ,
77 flags:: DataType ,
88 types:: Zval ,
99} ;
10+ use std:: hash:: { BuildHasher , Hash } ;
11+ use std:: { collections:: HashMap , convert:: TryFrom } ;
1012
11- use super :: super :: ZendHashTable ;
12-
13- // TODO: Generalize hasher
14- #[ allow( clippy:: implicit_hasher) ]
15- impl < ' a , V > TryFrom < & ' a ZendHashTable > for HashMap < String , V >
13+ impl < ' a , K , V , H > TryFrom < & ' a ZendHashTable > for HashMap < K , V , H >
1614where
15+ K : TryFrom < ArrayKey < ' a > , Error = Error > + Eq + Hash ,
1716 V : FromZval < ' a > ,
17+ H : BuildHasher + Default ,
1818{
1919 type Error = Error ;
2020
2121 fn try_from ( value : & ' a ZendHashTable ) -> Result < Self > {
22- let mut hm = HashMap :: with_capacity ( value. len ( ) ) ;
22+ let mut hm = Self :: with_capacity_and_hasher ( value. len ( ) , H :: default ( ) ) ;
2323
2424 for ( key, val) in value {
2525 hm. insert (
26- key. to_string ( ) ,
26+ key. try_into ( ) ? ,
2727 V :: from_zval ( val) . ok_or_else ( || Error :: ZvalConversion ( val. get_type ( ) ) ) ?,
2828 ) ;
2929 }
@@ -32,14 +32,15 @@ where
3232 }
3333}
3434
35- impl < K , V > TryFrom < HashMap < K , V > > for ZBox < ZendHashTable >
35+ impl < K , V , H > TryFrom < HashMap < K , V , H > > for ZBox < ZendHashTable >
3636where
3737 K : AsRef < str > ,
3838 V : IntoZval ,
39+ H : BuildHasher ,
3940{
4041 type Error = Error ;
4142
42- fn try_from ( value : HashMap < K , V > ) -> Result < Self > {
43+ fn try_from ( value : HashMap < K , V , H > ) -> Result < Self > {
4344 let mut ht = ZendHashTable :: with_capacity (
4445 value. len ( ) . try_into ( ) . map_err ( |_| Error :: IntegerOverflow ) ?,
4546 ) ;
@@ -52,12 +53,11 @@ where
5253 }
5354}
5455
55- // TODO: Generalize hasher
56- #[ allow( clippy:: implicit_hasher) ]
57- impl < K , V > IntoZval for HashMap < K , V >
56+ impl < K , V , H > IntoZval for HashMap < K , V , H >
5857where
5958 K : AsRef < str > ,
6059 V : IntoZval ,
60+ H : BuildHasher ,
6161{
6262 const TYPE : DataType = DataType :: Array ;
6363 const NULLABLE : bool = false ;
@@ -69,11 +69,10 @@ where
6969 }
7070}
7171
72- // TODO: Generalize hasher
73- #[ allow( clippy:: implicit_hasher) ]
74- impl < ' a , T > FromZval < ' a > for HashMap < String , T >
72+ impl < ' a , V , H > FromZval < ' a > for HashMap < String , V , H >
7573where
76- T : FromZval < ' a > ,
74+ V : FromZval < ' a > ,
75+ H : BuildHasher + Default ,
7776{
7877 const TYPE : DataType = DataType :: Array ;
7978
0 commit comments