Lending iterator trait and declarative macro for iteration

⚓ Rust    📅 2025-08-04    👤 surdeus    👁️ 10      

surdeus

Warning

This post was published 121 days ago. The information described in this article may have changed.

Since I found myself in the need to have lending iterators, which are exclusively used in for-loops like iteration, i.e. while let Some(…) = iter.next() { … } I whipped up a generic lending iterator trait and a declarative macro to facilitate iteration over iterator expressions.

The purpose of the macro is to improve ergonomics to not need to instantiate the iterator in a mutable variable manually each time and then call next() on it (and not accidentally re-instantiate the iterator on each iteration causing an infinite looping over the first item).

What are your thoughts on this?

1 post - 1 participant

Read full topic

🏷️ Rust_feed