rkyv / rkyv

Zero-copy deserialization framework for Rust
https://rkyv.org
MIT License
2.82k stars 167 forks source link

`Cell` and `RefCell` support #202

Open djkoloski opened 3 years ago

djkoloski commented 3 years ago

Supporting these types will make it easier to support modifiable archived types and help exercise the mutable API for rkyv.

Before diving in on this one, let's try to get some concrete use cases down. We need to make sure wee have at least one happy user.

LLBlumire commented 1 year ago

Here to register a use case. I am building a library that uses shared pointers under the hood to maintain a global reversible history of the state, and would like to support serializing and deserializing these data structures. This is not currently possible in rkyv due to the lack of Cell support, which is used to track the current version Rc<Cell<u64>> or Arc<AtomicU64>.

ureeves commented 11 months ago

Just mentioned this in one of our issues. We have a Merkle tree implementation that lazily computes the root. The data in the nodes of the tree is behind a RefCell, as such serializing this tree wholesale is not possible currently.

djkoloski commented 1 month ago

Supporting Cell and RefCell requires adding some more complexity to rkyv's trait system. Because &[u8] can be accessed as an archived type, we have to require that there are no types with interior mutability in that case. That requirement can be relaxed when accessing &mut [u8], but it remains to be seen how much of an ergonomics impact that would have.

djkoloski commented 1 week ago

I made a genuine effort to support interior mutability as a first-class citizen, but ran into some problems that can't be fixed. See #527 for details.