• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

davidcole1340 / ext-php-rs / 16401930518

20 Jul 2025 04:27PM UTC coverage: 26.829% (-0.1%) from 26.945%
16401930518

Pull #535

github

web-flow
Merge 9dbd1b190 into 25f508fc8
Pull Request #535: feat(array): BTreeMap conversion

0 of 18 new or added lines in 1 file covered. (0.0%)

97 existing lines in 3 files now uncovered.

1115 of 4156 relevant lines covered (26.83%)

5.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/types/array/conversions/hash_map.rs
1
use std::{collections::HashMap, convert::TryFrom};
2

3
use crate::{
4
    boxed::ZBox,
5
    convert::{FromZval, IntoZval},
6
    error::{Error, Result},
7
    flags::DataType,
8
    types::Zval,
9
};
10

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>
16
where
17
    V: FromZval<'a>,
18
{
19
    type Error = Error;
20

21
    fn try_from(value: &'a ZendHashTable) -> Result<Self> {
×
22
        let mut hm = HashMap::with_capacity(value.len());
×
23

24
        for (key, val) in value {
×
25
            hm.insert(
×
26
                key.to_string(),
×
27
                V::from_zval(val).ok_or_else(|| Error::ZvalConversion(val.get_type()))?,
×
28
            );
29
        }
30

31
        Ok(hm)
×
32
    }
33
}
34

35
impl<K, V> TryFrom<HashMap<K, V>> for ZBox<ZendHashTable>
36
where
37
    K: AsRef<str>,
38
    V: IntoZval,
39
{
40
    type Error = Error;
41

UNCOV
42
    fn try_from(value: HashMap<K, V>) -> Result<Self> {
×
43
        let mut ht = ZendHashTable::with_capacity(
UNCOV
44
            value.len().try_into().map_err(|_| Error::IntegerOverflow)?,
×
45
        );
46

UNCOV
47
        for (k, v) in value {
×
48
            ht.insert(k.as_ref(), v)?;
×
49
        }
50

UNCOV
51
        Ok(ht)
×
52
    }
53
}
54

55
// TODO: Generalize hasher
56
#[allow(clippy::implicit_hasher)]
57
impl<K, V> IntoZval for HashMap<K, V>
58
where
59
    K: AsRef<str>,
60
    V: IntoZval,
61
{
62
    const TYPE: DataType = DataType::Array;
63
    const NULLABLE: bool = false;
64

65
    fn set_zval(self, zv: &mut Zval, _: bool) -> Result<()> {
×
66
        let arr = self.try_into()?;
×
67
        zv.set_hashtable(arr);
×
68
        Ok(())
×
69
    }
70
}
71

72
// TODO: Generalize hasher
73
#[allow(clippy::implicit_hasher)]
74
impl<'a, T> FromZval<'a> for HashMap<String, T>
75
where
76
    T: FromZval<'a>,
77
{
78
    const TYPE: DataType = DataType::Array;
79

80
    fn from_zval(zval: &'a Zval) -> Option<Self> {
×
UNCOV
81
        zval.array().and_then(|arr| arr.try_into().ok())
×
82
    }
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc