Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upWhy Serializer and Deserializer implementors are missing in public API? #242
Comments
|
The reason for this is because the bincode Serializer and Deserializer are generic over many different "behaviors" for performance reasons. These behaviors currently include "is there a byte limit" and "which endianness should I use", but bincode was designed to support more of them. The reason that these options are done as generic parameters is because it's way faster than branching on every deserialization (pay only for what you use). Unfortunately, because these parameters are generic, I can't make the structure public because then adding more parameters would be a breaking change. I do plan on adding more parameters such as "size of enum tags" and "null terminate strings". For these reasons, the raw internal Deserializer / Serializer can not be exported without making every change a breaking change. However, it seems possible to use |
|
This is causing a problem for me as I'd like bincode to be compatible with my WIP crate pub struct DeserializerWrapper {
internal: Box<dyn Deserializer>,
}As a user of bincode I'm not super concerned about branching performance personally because most of the time when I'm serializing and deserializing I'm sending it out to disk or the network, and both of those are much worse bottle necks than CPU branching. |
|
Hm so I just tried to implement my idea and it's kind of a non-starter because even specifying the Unfortunately, the same problem also exists with the |
|
This also makes using serde_transcode impossible. |
|
I would love to use erased_serde with bincode, but I can't because of this. |
|
@TimonPost it looks like the workaround posted in #301 (using the currently unstable and undocumented serializeracceptor) would fix the issue. Would you be able to test that workaround to see if it solves your issue? |
|
@ZoeyR thanks !! I saw that solution today as well. I am not sure yet. I will try it soon. And update this post if it does work. |
|
Great! I'm working in parallel on a draft PR that would resolve this in a more traditional manner. If that ends up panning out we won't need the |
|
Closed as of #310 |
Majority of serde compatible data format crates export their
Serializer/Deserializerimplementors as opaque struct. Also serde documentation seems to mention that this is desired https://serde.rs/conventions.htmlAs i can see, currently the only way to obtain
Serializer/Deserializeris through hiddenSerializerAcceptor/DeserializerAcceptorwhich should not be considered stable API and also are not very convenient. Though for majority use cases user can be satisfied by wrapper functions, sometimes access to underlying trait implementors is needed(for example if you need to wrap in in someSerializer/Deserializeradapter with custom logic).