3 ms·
> Deleted { deleted_at: DateTime<Utc> }, What does this look like under the hood (in memory)? Does the compiler automatically generate a struct/union? Does the
by kortex 3y ago
> Deleted { deleted_at: DateTime<Utc> },
What does this look like under the hood (in memory)? Does the compiler automatically generate a struct/union? Does the value take up the same width regardless of state?
- deleted 3y ago[deleted]
- sowbug 3y agoYes; they take up the size of the largest variant. If you're concerned about that, you can Box<> the contents, and then each variant is effectively a same-sized pointer to something on the heap (plus some bookkeeping).
- goku12 3y agoReposting: https://cheats.rs/#memory-layout https://cheats.rs/#memory-layout > Does the value take up the same width regardless of state? Yes. As the other commenter mentioned, it's the size of the largest variant (same as a union in C) + a tag (almost the same as an enum in C). In some rare cases, the compiler even manages to optimize out the tag.