menu

large-variant

Disallow variants that disproportionately enlarge an inline union

An unusually large variant determines the storage required by every value of its union type. Instead, you SHOULD place the large payload behind Box when the smaller variants are common enough for the reduced inline size to matter. Keeping the payload inline can remain faster when the large variant dominates actual use.

Reported

1struct Packet {2    bytes: [uint8; 256];3}4 5newtype Message = int32 | Packet;

Accepted

1import { Box } from "destack:memory";2 3struct Packet {4    bytes: [uint8; 256];5}6 7newtype Message = int32 | Box<Packet>;