Expose types implementing serde::Serializer
and Deserializer
#729
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is sort of a proof-of-concept PR, I would like your input on it even though it's still in draft.
The goal here is to expose types implementing
serde::Serializer
andDeserializer
so thatbincode
could be used with https://docs.rs/erased-serde.Serializer
is straightforward, butDeserializer
can be exposed in two ways:D
, wherefor<'a> &'a mut D: Deserializer<'de>
. This is done e.g. inpostcard
. The problem here is that using such types generically involves passing around an ugly bound on lifetimes, which cannot be encapsulated in a trait. Also, dealing with such types inerased_serde
is somewhat complicated (albeit possible).D: Deserializer<'de>
. The downside of this is that in the format implementations (likebincode
)serde::Deserializer
is generally implemented for&mut Something
, or a wrapper of it (SerdeDecoder
inbincode
's case), because it has to be passed to nested list/struct/etc deserializers. So creating another implementation forD
involves writing down the massive trait impl one more time.So, I would like your input on the way to proceed with this. I see the following options:
bincode
at all. Feel free to close the PR then.D
, wherefor<'a> &'a mut D: Deserializer<'de>
. This requires minimum changes, but creates problems for the users, as described above.D: Deserializer<'de>
, writing down anotherDeserializer
impl (of which there are already two in the codebase).D: Deserializer<'de>
, relying on a helper crate that I made (https://docs.rs/serde-persistent-deserializer), which is implemented in this PR. The reason I put it there is that I want to create a similar PR for other formats, and I would like to avoid writingDeserializer
impls in each of them. I understand if you want to minimize the number of dependencies, then the contents of that crate can be brought in verbatim.(This PR currently does not expose
Serializer
, but that's easy, and I'll add it later if you decide not to go with Option 1).A few things about the PR itself.
Deserializer
impl inde_borrowed
, and it's almost possible by just replacingde_borrowed::SerdeDecoder
withde_owned::SerdeDecoder
, but a single test fails because these impls are slightly different. I am not sure if it's possible to merge them.de_owned::decode_from_slice()
("Note that this does not work with borrowed types like&str
or&[u8]
. For that use [borrow_decode_from_slice].") Seems to be working fine, as I can just callde_borrowed::borrow_decode_from_slice()
from it.