There was an error while loading. Please reload this page.
raise_if_stop!
protocol/iter.rs
1 parent 43be4e4 commit b6acfe0Copy full SHA for b6acfe0
vm/src/protocol/iter.rs
@@ -276,3 +276,20 @@ where
276
(self.length_hint.unwrap_or(0), self.length_hint)
277
}
278
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