Skip to content

Support while let #22

Open
Open
@omjadas

Description

@omjadas

I would find it useful for if_chain to also support while let.

if_chain! {
    if let Some(b) = a;
    while let Ok(c) = b;
    if let Some(d) = c;
    then {
        do_something_with_d(d);
    }
}

becomes:

if let Some(b) = a {
    while let Ok(c) = b {
        if let Some(d) = c {
            do_something_with_d(d);
        }
    }
}

I'm not sure how/if this should work with the else block. Perhaps something like the following could be done.

if_chain! {
    if let Some(b) = a;
    while let Ok(c) = b;
    if let Some(d) = c;
    then {
        do_something_with_d(d);
    } else {
        do_something_else();
    }
}

becomes:

if let Some(b) = a {
    let mut __executed = false;
    while let Ok(c) = b {
        __executed = true;
        if let Some(d) = c {
            do_something_with_d(d);
        } else {
            do_something_else();
        }
    }
    if !__executed {
        do_something_else();
    }
} else {
    do_something_else();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions