jonasbb / serde_with

This crate provides custom de/serialization helpers to use in combination with serde's `with`-annotation and with the improved `serde_as`-annotation.
https://docs.rs/serde_with
Apache License 2.0
636 stars 67 forks source link

Implement (De)Serialization for Pinned Smart Pointers #733

Closed Astralchroma closed 4 months ago

Astralchroma commented 4 months ago

Implements SerializeAs and DeserializeAs for Pin<Box<T>>, Pin<Rc<T>>, and Pin<Arc<T>>

Astralchroma commented 4 months ago

Seems the lints are bugged and are flagging the macros as unused when they are in fact used. I'll go ahead and add an #[allow(unused_macros)] for now.

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 66.55%. Comparing base (f4145e3) to head (04de4ce). Report is 14 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #733 +/- ## ========================================== + Coverage 66.49% 66.55% +0.06% ========================================== Files 38 38 Lines 2468 2473 +5 ========================================== + Hits 1641 1646 +5 Misses 827 827 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

jonasbb commented 4 months ago

Hi, thank you for submitting the PR. Everything looks good here. I extended the SerializeAs side with support for Pin<&'a T> and Pin<&'a mut T>.

I wonder if it is possible to support any Pin<T>, not just with specific pointer types. Pin::as_ref almost looks like it could work, but then is also return Deref::Target and I couldn't figure out how to make that work. On the deserialization side we need the well-known pointer types, since only they have safe conversions to Pin.

I leave this PR open for a day or two, in case you have an idea how to extend the serialization side, otherwise this looks good to merge.

Astralchroma commented 4 months ago

Yea, honestly not sure about how to go about extending it to work using Deref stuff. Had a go at it myself and couldn't really get very far with it. Might come back to it later as it seems like an interesting idea, however I'm just going to leave it for now I think.