chainable-if

Crates.iochainable-if
lib.rschainable-if
version0.1.1
sourcesrc
created_at2020-08-15 11:34:54.202628
updated_at2020-08-15 12:38:38.508921
description...
homepage
repositoryhttps://gitlab.com/IovoslavIovchev/chainable-if
max_upload_size
id276958
size15,535
Iovoslav Iovchev (IovoslavIovchev)

documentation

README

chainable-if

Crate Crate docs.rs

This crate provides the if_chain! macro -- a macro for composing long chains of if-else if-else statements.

It is intended to provide an alternative to writing if chains with match, such as:

match () {
    _ if some_condition => ...,
    _ if some_other_condition => ...,
    _ if some_third_condition => ...,
    _ => ...,
}

Example usage

While it is mainly intended for long chains, if_chain! can be used for simple if-else situations, such as:

if_chain! {
| some_condition => (/* some_condition is true */),
| _ => (/* the else branch */)
}

The earlier match example can be rewritten as:

if_chain! {
| some_condition => ...,
| some_other_condition => ...,
| some_third_condition => ...,
}

Note that the else branch is not required, since if_chain! simply gets expanded into:

if some_condition {
    ...
} else if some_other_condition }
    ...
} else if some_third_condition {
    ...
}
Commit count: 9

cargo fmt