#iterator #ad-hoc #in-place #impl

ad-hoc-iterator

Create an ad hoc iterator

3 releases

0.2.3 Sep 13, 2023
0.2.2 Sep 13, 2023
0.2.1 Sep 13, 2023

#1297 in Rust patterns

MIT license

5KB

Ad hoc Iterator

Docs.rsLib.rsCrates.io

The Iterator Trait is very useful. The problem ist just that we can't simply construct an iterator in-place, but rather have to define a struct, impl the Iterator trait for it, and then return a value of that struct. This crates exists to alleviate that inconvenience.


lib.rs:

Ad hoc Iterator

This is a very small crate providing a macro and a function that allow for conveniently creating iterators on the fly.

With the iterate macro of this crate, you can however do exactly that. See it's documentation for more information.

With the iterator_from function, you can directly create an iterator from an FnMut closure (which is exactly the same as what the iterate macro is doing behind the scenes).

No runtime deps