File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 11//! Represents an array in PHP. As all arrays in PHP are associative arrays, they are represented
22//! by hash tables.
33
4- use std:: { collections:: HashMap , u64} ;
4+ use std:: {
5+ collections:: HashMap ,
6+ convert:: { TryFrom , TryInto } ,
7+ u64,
8+ } ;
59
610use crate :: {
711 bindings:: {
@@ -324,12 +328,19 @@ where
324328}
325329
326330/// Implementation for converting a `ZendHashTable` into a `Vec` of given type.
331+ /// If the contents of the hash table cannot be turned into a type `T`, it wil skip over the item
332+ /// and return a `Vec` consisting of only elements that could be converted.
327333impl < ' a , V > From < ZendHashTable > for Vec < V >
328334where
329- V : From < Zval > ,
335+ V : TryFrom < Zval > ,
330336{
331337 fn from ( ht : ZendHashTable ) -> Self {
332- ht. into_iter ( ) . map ( |( _, _, v) | v. into ( ) ) . collect ( )
338+ ht. into_iter ( )
339+ . filter_map ( |( _, _, v) | match v. try_into ( ) {
340+ Ok ( v) => Some ( v) ,
341+ Err ( _) => None ,
342+ } )
343+ . collect ( )
333344 }
334345}
335346
You can’t perform that action at this time.
0 commit comments