Skip to main content

Module closed_enum

Module closed_enum 

Source
Expand description

closed_enum! — a fieldless enum, the list of its variants, and optionally their names, all written once.

A catalog enum is only useful if something can walk every variant: the runtime spawns each child in its catalog, the scheduler runs each filter plugin in its list, a test ticks each one, a decoder maps each stored code back. A hand-written ALL array next to the enum is a second list, and the second list is where a new variant goes missing — the enum compiles, every exhaustive match gets its arm, and the variant is simply never walked.

This macro generates the enum and ALL from the SAME token list, so ALL cannot miss a variant or hold one twice. Every per-variant fact stays an exhaustive match on the enum, which is a compile error (E0004) when a variant is added without its row.

ALL is in declaration order, and a fieldless enum’s discriminants are 0..N in declaration order, so ALL[v as usize] == v for every variant. A decoder that maps a stored code back to a variant relies on that.

§Why it lives here

This shape was derived three separate times — engenho-controllers, the scheduler’s filter_plugins! (which added name()), and a test-local copy in engenho-apiserver — and engenho-config could reach none of them, so KubeletBackendKind has a hand-written list. Three independent arrivals at one shape is the signal to extract, and the extraction belongs in the crate every other crate may depend on: this one is tokio-free and has no engenho edges, so no crate is barred from the macro by its dependency set.