jdonszelmann / label

MIT License
16 stars 1 forks source link

Extend the concept? #25

Closed moonheart08 closed 4 years ago

moonheart08 commented 4 years ago

It'd be neat/useful if Label could be used for same-type statics or consts, alongside functions. Not real sure how this'd work, you probably know better than I do.

jdonszelmann commented 4 years ago

Iteresting idea. I have been thinking about this as well. What would you propose the interface would be for that? I don't think you can iterate over structs because structs are types, and every struct has a different type. The reason this works is because functions with the same signature (which are not generic) have the same type. However, variables such as statics and consts might be possible. I will experiment with that a bit.

jdonszelmann commented 4 years ago

I think if I would support that, the final result would be very close to David Tolnay's Inventory

jdonszelmann commented 4 years ago

What do you think about a syntax close to this?

use label::create_label;

create_label!(
    static varname: usize;
);

#[varname::label]
static A: usize = 3;

#[varname::label]
static B: usize = 3;

fn main() {
    for i in varname::iter() {
        println!("{}", i);
    }
}

same for consts, iter_named would also be possible.

jdonszelmann commented 4 years ago

@moonheart08 #26