-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Rust Drivers
We have a variety of types that use Serde-based [de]serialization for wire format conversions; unfortunately, because Rust has no way to declare private impls this means that those impls become part of the public API surface. This is particularly unfortunate because there's often a significant delta between the fields the type exposes and the shape of the bson it serializes to, which would be very surprising for any users actually trying to use those impls in other contexts.
As a handwavy idea to work around this situation:
- We define a crate-private type that's just a generic wrapper: pub(crate) struct Wire<T>(T);
- For types that we want to serialize for wire format, we define impl Serialize for Wire<TheType>.
The main downside here is that we can't use derive for those types; however, we can use serde's "remote derive" feature to get around that by creating a mirror type in the impl.