Skip to content

Commit b6acfe0

Browse files
authored
Add raise_if_stop! macro for protocol/iter.rs (#5885)
1 parent 43be4e4 commit b6acfe0

File tree

2 files changed

+61
-93
lines changed

2 files changed

+61
-93
lines changed

‎vm/src/protocol/iter.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,20 @@ where
276276
(self.length_hint.unwrap_or(0), self.length_hint)
277277
}
278278
}
279+
280+
/// Macro to handle `PyIterReturn` values in iterator implementations.
281+
///
282+
/// Extracts the object from `PyIterReturn::Return(obj)` or performs early return
283+
/// for `PyIterReturn::StopIteration(v)`. This macro should only be used within
284+
/// functions that return `PyResult<PyIterReturn>`.
285+
#[macro_export]
286+
macro_rules! raise_if_stop {
287+
($input:expr) => {
288+
match $input {
289+
$crate::protocol::PyIterReturn::Return(obj) => obj,
290+
$crate::protocol::PyIterReturn::StopIteration(v) => {
291+
return Ok($crate::protocol::PyIterReturn::StopIteration(v))
292+
}
293+
}
294+
};
295+
}

0 commit comments

Comments
 (0)