From f449f4e4e119cdf4306cbaad495ecba50b6f32ce Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 24 Nov 2023 18:48:13 +0100 Subject: [PATCH] Cleanup --- guide/src/types/iterable.md | 7 +------ guide/src/types/iterator.md | 7 +++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/guide/src/types/iterable.md b/guide/src/types/iterable.md index cda816d..fec8072 100644 --- a/guide/src/types/iterable.md +++ b/guide/src/types/iterable.md @@ -20,7 +20,7 @@ that implements the `Traversable` interface. This means that any value that can #[php_function] pub fn test_iterable(mut iterable: Iterable) { for (k, v) in iterable.iter().expect("cannot rewind iterator") { - println!("k: {:?} v: {}", k, v.string().unwrap()); + println!("k: {} v: {}", k.string().unwrap(), v.string().unwrap()); } } # fn main() {} @@ -34,14 +34,11 @@ pub fn test_iterable(mut iterable: Iterable) { $generator = function() { yield 'hello' => 'world'; yield 'rust' => 'php'; - yield 'okk'; - yield new class {} => new class {}; }; $array = [ 'hello' => 'world', 'rust' => 'php', - 'okk', ]; test_iterable($generator()); @@ -53,8 +50,6 @@ Output: ```text k: hello v: world k: rust v: php -k: 0 v: okk k: hello v: world k: rust v: php -k: 0 v: okk ``` diff --git a/guide/src/types/iterator.md b/guide/src/types/iterator.md index ce0e9cf..4c53e67 100644 --- a/guide/src/types/iterator.md +++ b/guide/src/types/iterator.md @@ -23,7 +23,9 @@ If you want a more universal `iterable` type that also supports arrays, see [Ite #[php_function] pub fn test_iterator(iterator: &mut ZendIterator) { for (k, v) in iterator.iter().expect("cannot rewind iterator") { - println!("k: {:?} v: {}", k, v.string().unwrap()); + // Note that the key can be anything, even an object + // when iterating over Traversables! + println!("k: {} v: {}", k.string().unwrap(), v.string().unwrap()); } } # fn main() {} @@ -37,8 +39,6 @@ pub fn test_iterator(iterator: &mut ZendIterator) { $generator = function() { yield 'hello' => 'world'; yield 'rust' => 'php'; - yield 'okk'; - yield new class {} => new class {}; }; test_iterator($generator()); @@ -49,5 +49,4 @@ Output: ```text k: hello v: world k: rust v: php -k: 0 v: okk ```