Skip to content

Commit 678073a

Browse files
committed
Cleanup
1 parent 8d77b9e commit 678073a

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

guide/src/types/iterator.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ the variable. This means that any value, at the exception of an `array`, that ca
1111
a `foreach` loop can be converted into a `ZendIterator`. As an example, a `Generator` can be
1212
used but also a the result of a `query` call with `PDO`.
1313

14+
If you want a more universal `iterable` type that also supports arrays, see [Iterable](./iterable.md).
15+
1416
## Rust example
1517

1618
```rust,no_run

src/flags.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ use crate::ffi::{
88
CONST_CS, CONST_DEPRECATED, CONST_NO_FILE_CACHE, CONST_PERSISTENT, E_COMPILE_ERROR,
99
E_COMPILE_WARNING, E_CORE_ERROR, E_CORE_WARNING, E_DEPRECATED, E_ERROR, E_NOTICE, E_PARSE,
1010
E_RECOVERABLE_ERROR, E_STRICT, E_USER_DEPRECATED, E_USER_ERROR, E_USER_NOTICE, E_USER_WARNING,
11-
E_WARNING, IS_ARRAY, IS_CALLABLE, IS_CONSTANT_AST, IS_DOUBLE, IS_FALSE, IS_INDIRECT, IS_LONG,
12-
IS_ITERABLE,
13-
IS_MIXED, IS_NULL, IS_OBJECT, IS_PTR, IS_REFERENCE, IS_RESOURCE, IS_STRING, IS_TRUE,
14-
IS_TYPE_COLLECTABLE, IS_TYPE_REFCOUNTED, IS_UNDEF, IS_VOID, PHP_INI_ALL, PHP_INI_PERDIR,
15-
PHP_INI_SYSTEM, PHP_INI_USER, ZEND_ACC_ABSTRACT, ZEND_ACC_ANON_CLASS,
11+
E_WARNING, IS_ARRAY, IS_CALLABLE, IS_CONSTANT_AST, IS_DOUBLE, IS_FALSE, IS_INDIRECT,
12+
IS_ITERABLE, IS_LONG, IS_MIXED, IS_NULL, IS_OBJECT, IS_PTR, IS_REFERENCE, IS_RESOURCE,
13+
IS_STRING, IS_TRUE, IS_TYPE_COLLECTABLE, IS_TYPE_REFCOUNTED, IS_UNDEF, IS_VOID, PHP_INI_ALL,
14+
PHP_INI_PERDIR, PHP_INI_SYSTEM, PHP_INI_USER, ZEND_ACC_ABSTRACT, ZEND_ACC_ANON_CLASS,
1615
ZEND_ACC_CALL_VIA_TRAMPOLINE, ZEND_ACC_CHANGED, ZEND_ACC_CLOSURE, ZEND_ACC_CONSTANTS_UPDATED,
1716
ZEND_ACC_CTOR, ZEND_ACC_DEPRECATED, ZEND_ACC_DONE_PASS_TWO, ZEND_ACC_EARLY_BINDING,
1817
ZEND_ACC_FAKE_CLOSURE, ZEND_ACC_FINAL, ZEND_ACC_GENERATOR, ZEND_ACC_HAS_FINALLY_BLOCK,

src/types/iterable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::flags::DataType;
55
use crate::types::iterator::IterKey;
66
use crate::types::{ZendHashTable, ZendIterator, Zval};
77

8-
/// This type represents a PHP iterable, which can be either an array or an object implementing
9-
/// the Traversable interface.
8+
/// This type represents a PHP iterable, which can be either an array or an
9+
/// object implementing the Traversable interface.
1010
#[derive(Debug)]
1111
pub enum Iterable<'a> {
1212
Array(&'a ZendHashTable),

src/types/iterator.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::fmt::{Debug, Display, Formatter};
77

88
/// A PHP Iterator.
99
///
10-
/// In PHP, iterators are represented as zend_object_iterator. This allow user to iterate
11-
/// over object implementing Traversable interface using foreach.
10+
/// In PHP, iterators are represented as zend_object_iterator. This allow user
11+
/// to iterate over object implementing Traversable interface using foreach.
1212
pub type ZendIterator = zend_object_iterator;
1313

1414
impl ZendIterator {
@@ -29,8 +29,8 @@ impl ZendIterator {
2929

3030
/// Check if the current position of the iterator is valid.
3131
///
32-
/// As an example this will call the user defined valid method of the ['\Iterator'] interface.
33-
/// see <https://www.php.net/manual/en/iterator.valid.php>
32+
/// As an example this will call the user defined valid method of the
33+
/// ['\Iterator'] interface. see <https://www.php.net/manual/en/iterator.valid.php>
3434
pub fn valid(&mut self) -> bool {
3535
if let Some(valid) = unsafe { (*self.funcs).valid } {
3636
let valid = unsafe { valid(&mut *self) == ZEND_RESULT_CODE_SUCCESS };
@@ -47,13 +47,13 @@ impl ZendIterator {
4747

4848
/// Rewind the iterator to the first element.
4949
///
50-
/// As an example this will call the user defined rewind method of the ['\Iterator'] interface.
51-
/// see <https://www.php.net/manual/en/iterator.rewind.php>
50+
/// As an example this will call the user defined rewind method of the
51+
/// ['\Iterator'] interface. see <https://www.php.net/manual/en/iterator.rewind.php>
5252
///
5353
/// # Returns
5454
///
55-
/// Returns true if the iterator was successfully rewind, false otherwise. (when there is
56-
/// an exception during rewind)
55+
/// Returns true if the iterator was successfully rewind, false otherwise.
56+
/// (when there is an exception during rewind)
5757
pub fn rewind(&mut self) -> bool {
5858
if let Some(rewind) = unsafe { (*self.funcs).rewind } {
5959
unsafe {
@@ -66,13 +66,13 @@ impl ZendIterator {
6666

6767
/// Move the iterator forward to the next element.
6868
///
69-
/// As an example this will call the user defined next method of the ['\Iterator'] interface.
70-
/// see <https://www.php.net/manual/en/iterator.next.php>
69+
/// As an example this will call the user defined next method of the
70+
/// ['\Iterator'] interface. see <https://www.php.net/manual/en/iterator.next.php>
7171
///
7272
/// # Returns
7373
///
74-
/// Returns true if the iterator was successfully move, false otherwise. (when there is
75-
/// an exception during next)
74+
/// Returns true if the iterator was successfully move, false otherwise.
75+
/// (when there is an exception during next)
7676
pub fn move_forward(&mut self) -> bool {
7777
if let Some(move_forward) = unsafe { (*self.funcs).move_forward } {
7878
unsafe {
@@ -104,8 +104,8 @@ impl ZendIterator {
104104
///
105105
/// # Returns
106106
///
107-
/// Returns a new ['Zval'] containing the current key of the iterator if available
108-
/// , ['None'] otherwise.
107+
/// Returns a new ['Zval'] containing the current key of the iterator if
108+
/// available , ['None'] otherwise.
109109
pub fn get_current_key(&mut self) -> Option<Zval> {
110110
let get_current_key = unsafe { (*self.funcs).get_current_key? };
111111
let mut key = Zval::new();
@@ -178,7 +178,8 @@ impl<'a> Iterator for Iter<'a> {
178178
type Item = (IterKey, &'a Zval);
179179

180180
fn next(&mut self) -> Option<Self::Item> {
181-
// Call next when index > 0, so next is really called at the start of each iteration, which allow to work better with generator iterator
181+
// Call next when index > 0, so next is really called at the start of each
182+
// iteration, which allow to work better with generator iterator
182183
if self.zi.index > 0 && !self.zi.move_forward() {
183184
return None;
184185
}

src/types/zval.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ impl Zval {
267267
}
268268
}
269269

270-
/// Returns an iterable over the zval if it is an array or traversable. (is iterable)
270+
/// Returns an iterable over the zval if it is an array or traversable. (is
271+
/// iterable)
271272
pub fn iterable(&self) -> Option<Iterable> {
272273
if self.is_iterable() {
273274
Iterable::from_zval(self)
@@ -399,7 +400,8 @@ impl Zval {
399400
}
400401
}
401402

402-
/// Returns true if the zval is iterable (array or traversable), false otherwise.
403+
/// Returns true if the zval is iterable (array or traversable), false
404+
/// otherwise.
403405
pub fn is_iterable(&self) -> bool {
404406
let ptr: *const Self = self;
405407
unsafe { zend_is_iterable(ptr as *mut Self) }

0 commit comments

Comments
 (0)