Made a derive macro to easily get all of an enum's variants (crates.io)
from AshrafIbrahim03@programming.dev to rust@programming.dev on 29 May 01:11
https://programming.dev/post/31220231

I just learned the basics of macros and figured I’d give a shot trying to solve a problem I’ve had for a while. Theres just one derive trait in this crate, Variants, that when derived will generate a constant array that holds all of the enum’s variants along with a method that exposes a static reference to the constant array.

Give it a look, leave some feedback, maybe even open up a PR. I hope you like what you see!

#rust

threaded - newest

QueenMidna@lemmy.ca on 29 May 01:47 collapse

Why not just use strum?

AshrafIbrahim03@programming.dev on 29 May 02:19 collapse

I wanted to learn how to write a simple macro and how to publish a crate.

QueenMidna@lemmy.ca on 29 May 03:06 collapse

Fair enough!