Crates.io | for_ch |
lib.rs | for_ch |
version | 0.1.3 |
source | src |
created_at | 2021-08-14 04:50:47.251552 |
updated_at | 2021-08-15 05:20:25.329871 |
description | to flatten nested for-loop |
homepage | |
repository | https://github.com/TOETOE55/for_ch |
max_upload_size | |
id | 435963 |
size | 9,896 |
for_ch
named "for_each", "for_chain"(or even "4ch"), the crate provides a macro to flatten the nested for-loop and if-let.
for_ch! {
for x in 0..10; // forall x in 0..10,
// you can add a label before `for`
for y in x..10, for _ in 0..5; // forall y in x..x+5,
// zipping
if let Some(z) = foo(x, y).await?; // exists z. Some(z) = foo(x, y).await?
// if let guard
if x - y < z; // satisfies x - y < z
// guard
println!("x = {}, y = {}, z = {}", x, y, z);
}
would expend to
for x in 0..10 {
for y in (x..10).zip(0..5) {
if let Some(z) = foo(x, y).await? {
if x - y < z {
println!("x = {}, y = {}, z = {}", x, y, z);
}
}
}
}