move DNS constants to macro implementation#682
Open
withjannisNLnetLabs wants to merge 7 commits into
Open
Conversation
withjannisNLnetLabs
force-pushed
the
improve-new-compatibility
branch
5 times, most recently
from
June 25, 2026 14:12
659bbbc to
4ded3c2
Compare
bal-e
requested changes
Jun 26, 2026
bal-e
left a comment
Contributor
There was a problem hiding this comment.
I like the overall idea of using macros for deduplicating some work. I'm curious if they can be applied to more enum types in new-base so the PR removes more lines than it adds.
withjannisNLnetLabs
force-pushed
the
improve-new-compatibility
branch
9 times, most recently
from
July 9, 2026 14:34
e21cb60 to
0fdc786
Compare
withjannisNLnetLabs
force-pushed
the
improve-new-compatibility
branch
4 times, most recently
from
July 14, 2026 13:38
a6128fc to
435b4ba
Compare
domain::new
withjannisNLnetLabs
force-pushed
the
improve-new-compatibility
branch
2 times, most recently
from
July 14, 2026 15:56
c1de247 to
ac9de62
Compare
Different DNS constants have a similar structure and need common implementations. The added macro offers a readable interface to construct constants for an already defined type. The `known_values_define!` macro takes a list of constants which get defined. Additionally the functions `get_mnemonic` and `from_mnemonic` offer a simplified interface to access the constants. The `known_values_from_and_to_primitive` makes it easy to define the `From` implementations from and to the primitive value underlying the type.
`RType`, `RClass`, `QType` and `QClass` are defined through the `known_values_define` macro implementation. They all have a `Debug`, `Display` and `From` implementations. The (doc)tests verify the functionality and keep the Question and Record types in sync.
withjannisNLnetLabs
force-pushed
the
improve-new-compatibility
branch
2 times, most recently
from
July 21, 2026 17:06
f6655ac to
3fd762d
Compare
withjannisNLnetLabs
marked this pull request as ready for review
July 21, 2026 17:08
`SecAlg` is implemented through the `known_values_define` macro. It has a `Debug`, `Display` and `From` implementations.
`Nsec3HashAlgorithm` is implemented through the `known_values_define` macro. It has a `Debug`, `Display` and `From` implementations.
`ZoneMDScheme` is implemented through the `known_values_define` macro. It has a `Debug`, `Display` and `From` implementations.
`ZoneMDHashAlg` is implemented through the `known_values_define` macro. It has a `Debug`, `Display` and `From` implementations.
withjannisNLnetLabs
force-pushed
the
improve-new-compatibility
branch
from
July 21, 2026 20:40
3fd762d to
b8b8c2c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR simplifies the construction of constants i.e. assignments done by IANA.
It introduces a macro
known_values_definewhich defines the constants and stores all values and names defined in two lists. These lists are used to implementfrom_mnemonicandto_mnemonic, but could be used for other functions as well.Additionally the
known_values_from_and_to_primitivemacro which simplifies the conversion between the wrapper type and the wrapped primitive type.The following types have been touched:
RTypeRClassQTypeQClassNsec3HashAlgorithmSecAlgZoneMDSchemeZoneMDHashAlgThey are implemented using the above mentioned macros including sensible tests.
All these types now have a uniform
DisplayandDebugimplementation including doctests.Interface Changes
RTypeand others now also the number of the Type includes.Example:
RType::A(1), Before:RType::AMight not be complete.
Known Limitation/Imperfection
Debugoutput for types that don't have the same constant name as the mnemonic are not copy-pastable into code.For example
SecAlg::DSA(mnemonic) !=SecAlg::DSA_SHA1(rust constant).