lumol-org / soa-derive

Array of Struct to Struct of Array helpers in Rust
Apache License 2.0
416 stars 28 forks source link

Allow explicit name generation #18

Open kstrafe opened 5 years ago

kstrafe commented 5 years ago

Implicit name generation is something that is very dangerous, and we should almost always use hygienic, correctly scoped macros. So instead of making CheeseVec for the following:

#[derive(StructOfArray)]
struct Cheese {
   ...
}

I instead want to specify the resulting SOA name explicitly:

#[derive(StructOfArray(CheeseVec))]
struct Cheese {
   ...
}
Luthaf commented 5 years ago

So I agree that having an option to specify the generated structs names would be nice. I don't have a lot of time, but I would welcome a PR implementing it.

Syntax wise, I don't think it is possible to use a proc-macro like this

#[derive(StructOfArray(CheeseVec))]
struct Cheese {
   ...
}

Instead we would need to do

#[derive(StructOfArray)]
#[soa_derive(vec_name = "CheeseVec")]
struct Cheese {
   ...
}

However, as of today, the proc macro generate 7 structs from Cheese: CheeseVec, CheeseRef, CheeseMut, CheeseSlice, CheeseSliceMut, CheesePtr and CheesePtrMut. So either the could would need all of them to be configurable, or have some kind of prefix to use.