Printing layout of a type

From Type Sizes - The Rust Performance Book
there is an example of how to display sizes + padding for enum. Tried to do same for struct and it doesn't show any info.
What is the correct way to have layout of struct displayed?

There shouldn't be any difference between structs and enums for this. What exactly did you try?

I tried to change enum for struct. No output.

I mean what exactly did you write in your source file and how did you compile it?

fn main() {}
struct MY_Struct {
    val: i32,
    val_128: i128,

enum E {
    C(u64, u8, u64, u8),

called with:
RUSTFLAGS=-Zprint-type-sizes cargo +nightly build --release

-Zprint-type-sizes only prints sizes for types for which the layout is computed in the first place. This is normally only for types that are actually used. I'm not sure why the layout of E is computed though. I can see the sizes for MY_Struct if I add MY_Struct { val:0, val_128:0 }; to the main body.

Thank you for your help.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.