-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing new options could be simplified #43
Comments
I've thought about this for a little bit and indeed the implementation of new options is a little boilerplate-y. I'm not against a proc-macro. A few months ago I modified the forgot to paste the link: https://github.com/bluecatengineering/dhcproto/blob/num_enum_experiment/src/v4/options.rs#L211 |
Splitting of the number-to-enum and vice-versa into a common macro is something I've thought about too. Not the first time I've had this exact pattern of
Using a derive-macro like
I haven't looked into those bits yet. First thought is I would keep the decoding implementations outside of the macro, and define a generic implementation for e.g. |
My inclination is to leverage the macro to just generate the type and the From impls (1-4 & 7), and leave the decode/encode impls outside the macro, but we can discuss in the PR if you had something else. Happy to take the PR for the options macro if you want to submit that! |
Currently, new DHCP Options need to be added in 7 different places:
OptionCode
enumFrom<u8> for OptionCode
From<OptionCode> for u8
DhcpOption
enumdecode_inner
encode
From<&DhcpOption> for OptionCode
Aside from the extra typing, it increases the risk of human error and adds visual clutter.
Would you consider a PR that replaces these 7 steps (or a subsection of them) with a proc-macro?
I have a small prototype that looks like
That I'd be willing to PR after some small tweaks, if desired :)
The text was updated successfully, but these errors were encountered: