Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/st4s1k/rust-c4

Rust macro for C-like for-loop
https://github.com/st4s1k/rust-c4

for for-loop macro macros macros-rust rust rust-crate rust-lang rust-library rustlang

Last synced: 2 months ago
JSON representation

Rust macro for C-like for-loop

Awesome Lists containing this project

README

        

# c4

Rust C-like for-loop macro.

```rust
fn main() {
c4! {
for (let mut i = 1; i <= 10; i += 1) {
println!("9 * {:<2} = {}{}", i, i - 1, 10 - i);
}
}
c4! {
for (
let (mut i, mut j) = (0, 0),
let mut s = "some dummy word".to_string();
i * j <= s.len();
i += 1,
s = format!("{} {} {}", &s, i, j)
) {
j += 1;
println!("i: {}; j: {}; s: {}", i, j, s);
}
}
}
```