macro_rules! by_draft {
( $number:expr, $absent:expr, $( ($feat:literal, $variant:ident) => $named:expr ),+ $(,)? ) => { ... };
}Expand description
Answer a question per draft, with an arm for every draft and no catch-all.
by_draft! { draft, <absent>,
("draft07", Draft07) => <the answer draft-07 gives>,
...
("draft21", Draft21) => <the answer draft-21 gives>,
}draft is the draft number as the IETF writes it — 7 through 21, matching
crate::version::DraftVersion::number. <absent> is the answer for a
draft this crate does not implement and for one whose feature flag is off
in this build, which are two different facts with one honest answer: this
build has no table to consult. It is an expression rather than a value, so a
caller that needs to leave the function early can pass return None and a
caller that is already returning the right type can pass it directly.
Each row names its feature string and its crate::version::DraftVersion
variant, and the expansion writes two arms for the pair — one under
#[cfg(feature = ...)] carrying the answer, one under #[cfg(not(...))]
carrying <absent>. Every variant is therefore matched under every feature
set, which is what leaves the match with no _ arm and makes a new
DraftVersion variant a compile error here rather than a silent <absent>.
The answer expressions are transcribed at the invocation, so they read the
invocation’s own bindings — id, or a slice built above the call — exactly
as if they had been written into the match by hand.