[][src]Macro label::create_label

create_label!() { /* proc-macro */ }

Creates a new label.

create_label!(fn test() -> ());

To use a label, add an attribute to a function in the following style:

#[test::label]
fn my_function() {
    // contents
}

test is the name of your label (this has to be a full path to it. Labels can be imported). The annotation has to end with ::label, or otherwise it will not compile.

It is possible to create multipe labels in one invocation of the create_label macro. The syntax for this is as follows:

create_label!(
    fn test() -> ();
    fn test1(usize) -> (usize);
    fn test2(usize) -> (isize);
);

It is not supported to have two labels in scope with the same name, just like two structs in the same scope with the same name won't work either.

1 After a label is created, it is possible to iterate over all functions annotated with this label, using the iter function:

for func in test::iter() {
    // do something with the function
    func();
}

The order in which iteration occurs is not defined.

Alternatively, you can iterate over functions and their names using the iter_named() function:

for (name, func) in test::iter_named() {
    println!("name: {}", name);

    // do something with the function
    func();
}