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

davidcole1340 / ext-php-rs / 15788182852

20 Jun 2025 09:32PM UTC coverage: 22.034%. Remained the same
15788182852

Pull #460

github

web-flow
Merge d4fc01bb5 into 660f308c0
Pull Request #460: chore(clippy): flowing lifetimes warning and clippy::mut_from_ref

6 of 56 new or added lines in 13 files covered. (10.71%)

3 existing lines in 2 files now uncovered.

871 of 3953 relevant lines covered (22.03%)

2.35 hits per line

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

0.0
/src/types/iterable.rs
1
use super::array::Iter as ZendHashTableIter;
2
use super::iterator::Iter as ZendIteratorIter;
3
use crate::convert::FromZval;
4
use crate::flags::DataType;
5
use crate::types::{ZendHashTable, ZendIterator, Zval};
6

7
/// This type represents a PHP iterable, which can be either an array or an
8
/// object implementing the Traversable interface.
9
#[derive(Debug)]
10
pub enum Iterable<'a> {
11
    /// Iterable is an Array
12
    Array(&'a ZendHashTable),
13
    /// Iterable is a Traversable
14
    Traversable(&'a mut ZendIterator),
15
}
16

17
impl Iterable<'_> {
18
    /// Creates a new rust iterator from a PHP iterable.
19
    /// May return None if a Traversable cannot be rewound.
20
    // TODO: Check iter not returning iterator
21
    #[allow(clippy::iter_not_returning_iterator)]
NEW
22
    pub fn iter(&mut self) -> Option<Iter<'_>> {
×
23
        match self {
×
24
            Iterable::Array(array) => Some(Iter::Array(array.iter())),
×
25
            Iterable::Traversable(traversable) => Some(Iter::Traversable(traversable.iter()?)),
×
26
        }
27
    }
28
}
29

30
// TODO: Implement `iter_mut`
31
#[allow(clippy::into_iter_without_iter)]
32
impl<'a> IntoIterator for &'a mut Iterable<'a> {
33
    type Item = (Zval, &'a Zval);
34
    type IntoIter = Iter<'a>;
35

36
    fn into_iter(self) -> Self::IntoIter {
×
37
        self.iter().expect("Could not rewind iterator!")
×
38
    }
39
}
40

41
impl<'a> FromZval<'a> for Iterable<'a> {
42
    const TYPE: DataType = DataType::Iterable;
43

44
    fn from_zval(zval: &'a Zval) -> Option<Self> {
×
45
        if let Some(array) = zval.array() {
×
46
            return Some(Iterable::Array(array));
×
47
        }
48

49
        if let Some(traversable) = zval.traversable() {
×
50
            return Some(Iterable::Traversable(traversable));
×
51
        }
52

53
        None
×
54
    }
55
}
56

57
/// Rust iterator over a PHP iterable.
58
pub enum Iter<'a> {
59
    Array(ZendHashTableIter<'a>),
60
    Traversable(ZendIteratorIter<'a>),
61
}
62

63
impl<'a> Iterator for Iter<'a> {
64
    type Item = (Zval, &'a Zval);
65

66
    fn next(&mut self) -> Option<Self::Item> {
×
67
        match self {
×
68
            Iter::Array(array) => array.next_zval(),
×
69
            Iter::Traversable(traversable) => traversable.next(),
×
70
        }
71
    }
72
}
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

© 2025 Coveralls, Inc