Skip to main content

tolerant_enum

Macro tolerant_enum 

Source
macro_rules! tolerant_enum {
    (
        $(#[$meta:meta])*
        $vis:vis enum $name:ident {
            $(
                $(#[$vmeta:meta])*
                $variant:ident = $val:expr
            ),+ $(,)?
        }
    ) => { ... };
}
Expand description

Generates a string-backed enum that gracefully captures unknown variants.

The macro handles custom serde::Deserialize and serde::Serialize to ensure unknown string values are captured into an Unknown(String) variant instead of failing the parse. It also configures schemars and specta to skip the Unknown variant, maintaining a strictly closed public schema for producers.