Crates.io | for-loop-iterator |
lib.rs | for-loop-iterator |
version | 0.2.2 |
source | src |
created_at | 2023-03-31 02:59:02.562819 |
updated_at | 2023-04-01 05:21:59.424309 |
description | Iterators like traditional for loops |
homepage | |
repository | https://github.com/jaymehta-g/for-loop-iterator |
max_upload_size | |
id | 825904 |
size | 6,123 |
Allows you to create Rust iterators that act like traditional for loops!
Iterators will produce values just like for loops do
// A for loop in Java
for (int i = 0; i < 10; i++>) {
out.println(i);
}
// A Rust Iterator that performs the same function
ForLoopIterator::new(
0, // Initial Value
|i| i < &10, // Predicate that returns true if a value should be returned
|i| i + 1 // Function that, given a value from the iterator, returns the next one
)
.for_each( |i| {
println!("{i}");
});