I am reading this section of the Rust nomicon here repr(Rust) - The Rustonomicon and I am finding hard to get the point that is being made regarding monomorphizations and memory layout.

This is what I understand thus far.

In that section it says

By default, composite structures have an alignment equal to the maximum of their fields' alignments. Rust will consequently insert padding where necessary to ensure that all fields are properly aligned and that the overall type's size is a multiple of its alignment.

Then it gave this as an example

```
struct A {
a: u8,
b: u32,
c: u16,
}
```

So the overall type size should be a multiple of 32 right? Given the maximum size is 32. It then gave an example of how this type can be laid out ensuring this holds true. The first example was

```
struct A {
a: u8,
_pad1: [u8; 3], // to align `b`
b: u32,
c: u16,
_pad2: [u8; 2], // to make overall size multiple of 4
}
```

Which eventually gives 8 + 24 + 32 + 16 + 16 = 96 and 96 is a multiple of 32, so it checks out.

But if we sum the sizes of the individual fields, we get 8 + 32 + 16 = 56, which is 8 less 64 and 64 is also a multiple of 32. So another way to do this is to pad with just 8. And the this was given as the second example

```
struct A {
b: u32,
c: u16,
a: u8,
_pad: u8,
}
```

Up till now, this sort of make sense.

Then it introduced the interplay of monomorphizations and memory layout by giving the generic struct

```
struct Foo<T, U> {
count: u16,
data1: T,
data2: U,
}
```

and makes the argument that `struct Foo<u16, u32>`

is already aligned while `struct Foo<u32, u16>`

is not.

So for `struct Foo<u16, u32>`

that would be

```
struct Foo<u16, u32> {
count: u16,
data1: u16,
data2: u32,
}
```

Largest field is 32, so total size should be a multiple of 32, and this is the case with 16+16+32 = 64.

While it says `struct Foo<u32, u16>`

would have to be padded this way

```
struct Foo<u32, u16> {
count: u16,
_pad1: u16,
data1: u32,
data2: u16,
_pad2: u16,
}
```

and the book makes the case that this wastes space. But I don't get why it even needs to be padded this way? Given that `struct Foo<u32, u16>`

is

```
struct Foo<u16, u32> {
count: u16,
data1: u32,
data2: u16,
}
```

This also adds up to 64, a multiple of 32. So why does `struct Foo<u16, u32>`

require padding but `struct Foo<u16, u32> `

does not?