Skip to content

Commit 87f1503

Browse files
committed
Fixed HashTable -> Vec
1 parent 3917c41 commit 87f1503

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/php/types/array.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
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

610
use 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.
327333
impl<'a, V> From<ZendHashTable> for Vec<V>
328334
where
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

0 commit comments

Comments
 (0)