Skip to main content

## VARIANT_SIZE_DIFFERENCES

# Static VARIANT_SIZE_DIFFERENCES

Source

    static VARIANT_SIZE_DIFFERENCES: &Lint

Expand description

The `variant_size_differences` lint detects enums with widely varying variant sizes.

#### §Example

ⓘ

    #![deny(variant_size_differences)]
    enum En {
        V0(u8),
        VBig([u8; 1024]),
    }

{{produces}}

#### §Explanation

It can be a mistake to add a variant to an enum that is much larger than the other variants, bloating the overall size required for all variants. This can impact performance and memory usage. This is triggered if one variant is more than 3 times larger than the second-largest variant.

Consider placing the large variant’s contents on the heap (for example via `Box`) to keep the overall size of the enum itself down.

This lint is “allow” by default because it can be noisy, and may not be an actual problem. Decisions about this should be guided with profiling and benchmarking.