rust-console / gba

A crate that helps you make GBA games
https://docs.rs/gba
Apache License 2.0
658 stars 50 forks source link

Use paste to remove a whole bunch of repetition #166

Closed Sp00ph closed 2 years ago

Sp00ph commented 2 years ago

The different macros used to define fields all had to specify both the getter name and the with-name, which seemed to me like needless repetition, as the with-name was always just with_$name, so with the use of the paste crate I've made it so that you can only give it the field name and by default it automatically uses with_$name as the with-method name. I haven't removed the old macro rule, so if you ever want to use a different with-name for some reason, that's still possible.

Sp00ph commented 2 years ago

Using paste we might also be able to merge the struct definition and the getter / setter definitions, i might look into it later.

Sp00ph commented 2 years ago

Actually nevermind, i forgot the struct definition is just a simple one liner, probably not worth it to make a more complicated macro then.

Lokathor commented 2 years ago

I don't think that using a dependency here is a good trade. The amount of extra typing that I end up doing to have the "with" methods is nearly none. Using a multi-line select in VSCode I just pick out the getter names, then it's something like: left arrow, , with_, then paste the names in, and it's all done.

Sp00ph commented 2 years ago

What's the problem with a small build time dependency like paste? I mean I kinda get your point, but the paste compile time is completely by the time it takes to compile core anyways. Also this way there's no potential for naming inconsistency by way of typos, though in your case specifically using copy+paste obviously also makes that a non-issue.

Lokathor commented 2 years ago

hm, I hadn't considered that it can build in parallel with core. I suppose it's fine then.

Lokathor commented 2 years ago

I'll merge it for now and maybe later I'll double check that rebuild times aren't notably affected (probably they aren't).

Lokathor commented 2 years ago

I think I misunderstood earlier and thought that this was going to be a dev-dependency rather than a normal dependency. I'd strongly perfer that 100% of the gba build tree be Zlib compatible if possible. That puts me back on the fence, but i'll keep it for now.

Sp00ph commented 2 years ago

Oh right, I didn't think about licenses, sorry about that.

Lokathor commented 2 years ago

I'm probably being a little too picky, and it is nicer during the initial development to only write each thing once.

I'll probably finish all the main MMIO structs like this and then do a pass of the "multi-line copy and paste" thing once at the end.