Skip to content

Implement Serde support - #33

Open
LPGhatguy wants to merge 3 commits into
mainfrom
serde-support
Open

Implement Serde support#33
LPGhatguy wants to merge 3 commits into
mainfrom
serde-support

Conversation

@LPGhatguy

@LPGhatguy LPGhatguy commented Jan 7, 2022

Copy link
Copy Markdown
Owner

Closes #32.

This implements Serde support for thunderdome::Arena<T> for any T that has Serde support. Documentation and tests show pretty well what the format is. Notably, empty slots are serialized as well as occupied ones in order to preserve their generation.

I've bumped the crate's MSRV to 1.36.0 to gain support for MaybeUninit, used by Serde. It's a small bump, so I'm not very worried about it.

@tyler274

tyler274 commented Oct 22, 2022

Copy link
Copy Markdown

You should be able to use matches now since you bumped the MSRV to 1.47, as matches is stable since 1.42. I unintentionally made this change following guidance from Clippy in my typed index PR.

@LPGhatguy

Copy link
Copy Markdown
Owner Author

This PR has rotted a fair bit and needs a lot of love. In my games and other projects, I don't ever serialize a thunderdome::Arena. I've historically had a few hangups on serializing generational arenas that I didn't voice anywhere.

If we want to serialize the arena with generations intact:

  • Serialization must expose details about the storage layout of the arena (i.e. generation + value for each slot)
  • With user-controlled generations in a serialized arena, old indices could get resurrected, which may be a surprising problem for a lot of applications.
  • We don't want to serialize the freelist, but not serializing it means that round-tripping an arena through serialization loses some information and changes the allocation of future indices.

...but if we don't serialize generations and treat it as a Vec<T>:

  • Existing indices become invalid, and if we also compacted (like if you serialized only occupied slots) then locations in the arena are also lost.

@mikwielgus

Copy link
Copy Markdown
Contributor

I will be going towards serializing generations but not freelist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Serde Support

3 participants