I have a use case where I want to get the sum of the sizes of the struct's members in bytes.
Due to alignment, std::mem::size_of() is not an option.
I.e. I am looking for a function like accumulated_size<T>():
Is there something in the standard library, that I'm missing or some de-facto standard crate for this?
I do not need or want to use #[repr(packed)] btw.
I had a similar use case for which I wrote le-stream and le-stream-derive.
However, my current use case needs to buffer data instead of streaming it, so I need to know the size at compile time.
I now quickly scrabbled my own implementations: buf_sized and buf_sized_derive
Indeed. I do not want #[repr(packed)] since the software will be used on a wonky ARM device, and I don't want the structures to cause UB when loaded into memory. I just need the size for when writing bytes into a buffer which then later will be written to a serial port.