The memory size of the struct _Add here would be the size of _a and _b combined, in other words for any type T and length of n, [T; n] has the size of n * size_of::<T>(), and since here T is u8 and its size is just 1 byte; hence [u8; n] is just n bytes. Using this; the size of _Add would be the size of [u8; A] (A bytes) and the size of [u8; B] (B bytes); will result in total is A+B bytes.
The memory size of the struct
_Addhere would be the size of_aand_bcombined, in other words for any typeTand length ofn,[T; n]has the size ofn * size_of::<T>(), and since hereTisu8and its size is just1byte; hence[u8; n]is justnbytes. Using this; the size of_Addwould be the size of[u8; A](A bytes) and the size of[u8; B](B bytes); will result in total isA+Bbytes.Yes but this is where I'm lost. Wouldn't be the returned value 2 in every case?
No, in the test case,
A = 40means[0u8; 40]that also means40 bytes, andB = 2which is[0u8; 2]that's 2 bytes, which is total of42bytes.Ah indeed, thanks! I misunderstood the syntax.
edit : that's a really smart solution btw, thanks for sharing