https://heycam.github.io/webidl/#idl-enums
enum MealType { "rice", "noodles", "other" };
These are always string literals.
I don't think we want to translate these into Rust enums because Rust is allowed to assume they are exhaustive, meaning that if the definitions are extended in the future, we would get UB in Rust.
Instead, we can translate it into something like:
mod MealType {
const Rice: &'static str = "rice";
// ...
}
// usage:
foo(MealType::Rice);
How would it cause undefined behavior? I assume that it would do some runtime validation, to ensure correctness (some browsers might support only some of the enums, and some browsers might have extra browser-specific enums, so I think runtime validation is a good idea regardless).
I would also vote for mapping them to rust enum's, especially given that the non-exhaustive enum's rfc was accepted and has already been implemented in the nightly compiler.
SGTM!
Most helpful comment
I would also vote for mapping them to rust enum's, especially given that the non-exhaustive enum's rfc was accepted and has already been implemented in the nightly compiler.