mirror of
https://codeberg.org/icewind/php-literal-parser.git
synced 2026-06-03 10:34:08 +02:00
add iterators
This commit is contained in:
parent
4edf5edcd3
commit
370e959c6c
1 changed files with 19 additions and 0 deletions
19
src/lib.rs
19
src/lib.rs
|
|
@ -194,6 +194,25 @@ impl Value {
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Iterate over array key and value pairs if it is an array
|
||||||
|
pub fn iter(&self) -> impl Iterator<Item = (&Key, &Value)> {
|
||||||
|
let map = match self {
|
||||||
|
Value::Array(map) => Some(map),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
map.into_iter().flat_map(|map| map.iter())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Iterate over array keys if it is an array
|
||||||
|
pub fn keys(&self) -> impl Iterator<Item = &Key> {
|
||||||
|
self.iter().map(|(key, _value)| key)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Iterate over array values if it is an array
|
||||||
|
pub fn values(&self) -> impl Iterator<Item = &Value> {
|
||||||
|
self.iter().map(|(_key, value)| value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<bool> for Value {
|
impl PartialEq<bool> for Value {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue