Macro tear::last[][src]

macro_rules! last {
    () => { ... };
    ( $id:expr ) => { ... };
}

Dirty shortcut for creating a Looping::Break

Description

If called with no arguments, it breaks the current loop.

If called with the label index, it breaks the corresponding loop (see twist!).

Used for writing short twist! statements that break from an enclosing loop. See examples.

Note that this macro will fail to compile if twist! can break with a value or when using twist -label.

Examples

use tear::{twist, last};

loop {
    twist! { last!() }
    panic!("We should break before this")
}

'a: loop {
    loop {
        twist! { -label 'a | last!(0) }
       panic!("We should break from the outer loop")
    }
}

Naming

It is named after the equivalent of break in Perl. break is a keyword so we can’t name the macro break! unless we use r#break!.

See also