loop_chain 0.1.1

Macro for writing nested Loop expressions
Documentation
  • Coverage
  • 16.67%
    1 out of 6 items documented1 out of 1 items with examples
  • Size
  • Source code size: 13.75 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.17 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • TaKO8Ki/loop_chain
    6 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • TaKO8Ki

loop_chain

Macro for writing nested Loop expressions

github workflow status crates docs

Usage | Examples | Docs

Dependencies

[dependencies]
loop_chain = "0.1.1"

Usage

For expression

fn main() {
    loop_chain::loop_chain! {
        for width in 0..10;
        for height in 0..10;
        then {
            println!("width: {}, height: {}", width, height);
        }
    }
}

the generated code will be the following:

fn main() {
    for width in 0..10 {
        for height in 0..10 {
            println!("width: {}, height: {}", width, height);
        }
    }
}

While expression

fn main() {
    let mut foo = 0;
    loop_chain::loop_chain! {
        while foo < 3;
        foo += 1;
        for x in 0..10;
        then {
            println!("foo: {}, x: {}", foo, x);
        }
    }
}

the generated code will be the following:

fn main() {
    let mut foo = 0;
    while foo < 3 {
        for x in 0..10 {
            println!("foo: {}, x: {}", foo, x);
        }
    }
}

While let expression

fn main() {
    let mut foo = (0..10).collect::<Vec<u8>>();
    loop_chain::loop_chain! {
        while let Some(v) = foo.pop();
        for x in 0..10;
        then {
            println!("v: {}, x: {}", v, x);
        }
    }
}

the generated code will be the following:

fn main() {
    let mut foo = (0..10).collect::<Vec<u8>>();
    while let Some(v) = foo.pop() {
        for x in 0..10 {
            println!("v: {}, x: {}", v, x);
        }
    }
}

Loop expression

fn main() {
    let mut foo = 0;
    loop_chain::loop_chain! {
        loop;
        foo += 1;
        if foo > 3 {
            break
        };
        for x in 0..10;
        then {
            println!("foo: {}, x: {}", foo, x);
        }
    }
}

the generated code will be the following:

fn main() {
    let mut foo = 0;
    loop {
        foo += 1;
        if foo > 3 {
            break
        };
        for x in 0..10 {
            println!("foo: {}, x: {}", foo, x);
        }
    }
}

Reference