quote in THE BOOK:
"To determine how much space to allocate for a Message value, Rust goes through each of the variants to see which variant needs the most space. "
But for me, the sizes of any of the two enums can't be determined. Because we can have a String type in Message.
I also wonder that is that a enum is always stored on the heap? If so, why the size should be determined?
The might be a silly question. But please help me. Thanks in advance!
In this case, even though the number of bytes behind buffer isn't known, we do know the size of a pointer and two usizes.
Values are never implicitly stored on the heap. There will always be an explicit pointer field somewhere (e.g. within the definition for String or Box).
Yes, but ArrayVec doesn't let you hold information of arbitrary size. It's just a wrapper around a fixed-size array which handles uninitialized memory for you.