How to force a match statement to be matched against all variants of a enum (if you aren't matching the enum itself)

In Rust when matching a string or number
is there any way to enforce rust to make you match every varient of the enum to values of that string/number?

        let finalnamespace = match unwrapped_namespace {
                        0 => TopicTag::None,
                        1 => TopicTag::Configure,
                        _ => TopicTag::None
                    };

e.g, unwrapped_namespace is a number thats supposed to be matched against every varrient of TopicTag
anny way to force this?

Not directly. You can use a macro library like strum or exhaust to write a test that iterates over every TopicTag variant, convert it to its corresponding number, then test that the code converts that number to that same variant.

1 Like