Uploaded image for project: 'Rust Driver'
  1. Rust Driver
  2. RUST-1978

Hide serde usage for server command serialization

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • 4.0.0
    • 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:

      1. We define a crate-private type that's just a generic wrapper: pub(crate) struct Wire<T>(T);
      2. 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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            abraham.egnor@mongodb.com Abraham Egnor
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: