Nnubes256 / ruby-marshal

A deserialization library for Ruby's marshalling format.
BSD 2-Clause "Simplified" License
2 stars 0 forks source link

Improvement of FromRubyMarshal ergonomics #1

Open Nnubes256 opened 1 year ago

Nnubes256 commented 1 year ago

So I think I've had an idea to make possible having the deserializer be built-in into RubyType that sidesteps the double mutable borrow issues I had with it (see https://discord.com/channels/273534239310479360/1058530213585236019/1058758259428839425 on the Rust community Discord server).

Really the problem with the approach I took before is two-fold:

However, this week I thought about it and I think there's a way to solve that particular problem. For this to work, I think you need both a RubyType<'de, 'deser> and a RubyType<'de> we will call the latter "RawRubyType<'de>".

What this implies is that you have two ways of getting the next element to deserialize:

And implementations can mix and match depending on what they do. Consider RubyArrayIter for example:

I think that with this I'd be able to solve all footguns the library has so far:

Nnubes256 commented 1 year ago

...yeah no. I realized way too late that Rust doesn't have linear types, so having a Drop implementation for RubyArrayIter/RubyMapIter that safely skips the iterator on drop is not really possible.