-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(iterator): add iterable, add method to get traversable or iterable
- Loading branch information
Showing
10 changed files
with
163 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,6 +160,7 @@ bind! { | |
IS_UNDEF, | ||
IS_VOID, | ||
IS_PTR, | ||
IS_ITERABLE, | ||
MAY_BE_ANY, | ||
MAY_BE_BOOL, | ||
PHP_INI_USER, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use super::array::Iter as ZendHashTableIter; | ||
use super::iterator::Iter as ZendIteratorIter; | ||
use crate::convert::FromZval; | ||
use crate::flags::DataType; | ||
use crate::types::iterator::IterKey; | ||
use crate::types::{ZendHashTable, ZendIterator, Zval}; | ||
|
||
#[derive(Debug)] | ||
pub enum Iterable<'a> { | ||
Array(&'a ZendHashTable), | ||
Traversable(&'a mut ZendIterator), | ||
} | ||
|
||
impl<'a> Iterable<'a> { | ||
pub fn iter(&mut self) -> Iter { | ||
match self { | ||
Iterable::Array(array) => Iter::Array(array.iter()), | ||
Iterable::Traversable(traversable) => Iter::Traversable(traversable.iter()), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> FromZval<'a> for Iterable<'a> { | ||
const TYPE: DataType = DataType::Iterable; | ||
|
||
fn from_zval(zval: &'a Zval) -> Option<Self> { | ||
if let Some(array) = zval.array() { | ||
return Some(Iterable::Array(array)); | ||
} | ||
|
||
if let Some(traversable) = zval.traversable() { | ||
return Some(Iterable::Traversable(traversable)); | ||
} | ||
|
||
None | ||
} | ||
} | ||
|
||
pub enum Iter<'a> { | ||
Array(ZendHashTableIter<'a>), | ||
Traversable(ZendIteratorIter<'a>), | ||
} | ||
|
||
impl<'a> Iterator for Iter<'a> { | ||
type Item = (IterKey, &'a Zval); | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
match self { | ||
Iter::Array(array) => array.next(), | ||
Iter::Traversable(traversable) => traversable.next(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters