File tree Expand file tree Collapse file tree 2 files changed +71
-0
lines changed
src/types/array/conversions Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 4545 }
4646}
4747
48+ impl < ' a , V > FromZval < ' a > for BTreeSet < V >
49+ where
50+ V : FromZval < ' a > + Ord ,
51+ {
52+ const TYPE : DataType = DataType :: Array ;
53+
54+ fn from_zval ( zval : & ' a Zval ) -> Option < Self > {
55+ zval. array ( ) . and_then ( |arr| arr. try_into ( ) . ok ( ) )
56+ }
57+ }
58+
4859impl < V > IntoZval for BTreeSet < V >
4960where
5061 V : IntoZval ,
5869 Ok ( ( ) )
5970 }
6071}
72+
73+ #[ cfg( test) ]
74+ #[ cfg( feature = "embed" ) ]
75+ #[ allow( clippy:: unwrap_used) ]
76+ mod tests {
77+ use std:: collections:: BTreeSet ;
78+
79+ use crate :: boxed:: ZBox ;
80+ use crate :: convert:: { FromZval , IntoZval } ;
81+ use crate :: embed:: Embed ;
82+ use crate :: error:: Error ;
83+ use crate :: types:: { ArrayKey , ZendHashTable , Zval } ;
84+
85+ #[ test]
86+ fn test_hash_table_try_from_btree_set ( ) {
87+ Embed :: run ( || {
88+ let mut set = BTreeSet :: new ( ) ;
89+ set. insert ( "one" ) ;
90+ let ht: ZBox < ZendHashTable > = set. try_into ( ) . unwrap ( ) ;
91+ assert_eq ! ( ht. len( ) , 1 ) ;
92+ assert ! ( ht. get( 0 ) . is_some( ) ) ;
93+ } ) ;
94+ }
95+ }
Original file line number Diff line number Diff line change 4848 }
4949}
5050
51+ impl < ' a , V , H > FromZval < ' a > for HashSet < V , H >
52+ where
53+ V : FromZval < ' a > + Eq + Hash ,
54+ H : BuildHasher + Default ,
55+ {
56+ const TYPE : DataType = DataType :: Array ;
57+
58+ fn from_zval ( zval : & ' a Zval ) -> Option < Self > {
59+ zval. array ( ) . and_then ( |arr| arr. try_into ( ) . ok ( ) )
60+ }
61+ }
62+
5163impl < V , H > IntoZval for HashSet < V , H >
5264where
5365 V : IntoZval ,
6274 Ok ( ( ) )
6375 }
6476}
77+
78+ #[ cfg( test) ]
79+ #[ cfg( feature = "embed" ) ]
80+ #[ allow( clippy:: unwrap_used) ]
81+ mod tests {
82+ use std:: collections:: HashSet ;
83+
84+ use crate :: boxed:: ZBox ;
85+ use crate :: convert:: { FromZval , IntoZval } ;
86+ use crate :: embed:: Embed ;
87+ use crate :: error:: Error ;
88+ use crate :: types:: { ArrayKey , ZendHashTable , Zval } ;
89+
90+ #[ test]
91+ fn test_hash_table_try_from_hash_set ( ) {
92+ Embed :: run ( || {
93+ let mut set = HashSet :: new ( ) ;
94+ set. insert ( "one" ) ;
95+ let ht: ZBox < ZendHashTable > = set. try_into ( ) . unwrap ( ) ;
96+ assert_eq ! ( ht. len( ) , 1 ) ;
97+ assert ! ( ht. get( 0 ) . is_some( ) ) ;
98+ } ) ;
99+ }
100+ }
You can’t perform that action at this time.
0 commit comments