File tree Expand file tree Collapse file tree 3 files changed +69
-0
lines changed
src/types/array/conversions Expand file tree Collapse file tree 3 files changed +69
-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 :: embed:: Embed ;
81+ use crate :: types:: ZendHashTable ;
82+
83+ #[ test]
84+ fn test_hash_table_try_from_btree_set ( ) {
85+ Embed :: run ( || {
86+ let mut set = BTreeSet :: new ( ) ;
87+ set. insert ( "one" ) ;
88+ let ht: ZBox < ZendHashTable > = set. try_into ( ) . unwrap ( ) ;
89+ assert_eq ! ( ht. len( ) , 1 ) ;
90+ assert ! ( ht. get( 0 ) . is_some( ) ) ;
91+ } ) ;
92+ }
93+ }
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 :: embed:: Embed ;
86+ use crate :: types:: ZendHashTable ;
87+
88+ #[ test]
89+ fn test_hash_table_try_from_hash_set ( ) {
90+ Embed :: run ( || {
91+ let mut set = HashSet :: new ( ) ;
92+ set. insert ( "one" ) ;
93+ let ht: ZBox < ZendHashTable > = set. try_into ( ) . unwrap ( ) ;
94+ assert_eq ! ( ht. len( ) , 1 ) ;
95+ assert ! ( ht. get( 0 ) . is_some( ) ) ;
96+ } ) ;
97+ }
98+ }
Original file line number Diff line number Diff line change 77//! ## Supported Collections
88//!
99//! - `BTreeMap<K, V>` ↔ `ZendHashTable` (via `btree_map` module)
10+ //! - `BTreeSet<V>` ↔ `ZendHashTable` (via `btree_set` module)
1011//! - `HashMap<K, V>` ↔ `ZendHashTable` (via `hash_map` module)
12+ //! - `HashSet<V>` ↔ `ZendHashTable` (via `hash_set` module)
1113//! - `Vec<T>` and `Vec<(K, V)>` ↔ `ZendHashTable` (via `vec` module)
1214
1315mod btree_map;
You can’t perform that action at this time.
0 commit comments