dowhile_rs

Crates.iodowhile_rs
lib.rsdowhile_rs
version0.1.2
created_at2025-01-05 16:01:01.269546+00
updated_at2025-01-06 10:53:21.53843+00
descriptionDo while macro for rust with labels and nesting support
homepagehttps://github.com/nstrmx/dowhile-rs
repositoryhttps://github.com/nstrmx/dowhile-rs
max_upload_size
id1504891
size5,904
Den (nstrmx)

documentation

README

Installation

cargo add dowhile_rs

Example usage

let mut x = 6;
dowhile!({
    println!("x = {x}");
    x += 1;
} x < 3);

// x = 6

Pattern matching

let mut x = Some(6);
dowhile!({
    println!("x = {x:?}");
    x = Some(x.unwrap_or(0) + 1);
} let Some(..3) = x);

// x = Some(6)
let mut x = Some(6);
dowhile!({
    println!("x = {x:?}");
    x = Some(x.unwrap_or(0) + 1);
} let Some(val) = x => val < 3);

// x = Some(6)

Nested

let mut x = 4;
dowhile!({
    println!("x = {x}");

    let mut y = 0;
    dowhile!({
        println!("y = {y}");
        y += 1;
    } y < x);
    
    x += 1;
} x < 4);

// x = 4
// y = 0
// y = 1
// y = 2
// y = 3

Labeled

let mut x = 10;
dowhile!('first: {
    println!("x = {x}");

    let mut y = 0;
    dowhile!('second: {
        if y == 4 {
            break 'first;
        }
        println!("y = {y}");
        y += 1;
    } y < x);
    
    x += 1;
} x < 6);

// x = 10
// y = 0
// y = 1
// y = 2
// y = 3
Commit count: 17

cargo fmt