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

Add serde_with integration for composable serde helpers

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed
    • Unknown
    • Resolution: Fixed
    • None
    • bson-2.1.0
    • BSON
    • None

    Description

      The crate serde_with provides the SerializeAs and DeserializeAs traits, which we can implement on our types to allow for composable serde(with = "") attributes. These currently aren't supported in vanilla serde.

      This will enable the following (which currently isn't possible):

      #[serde_as]
      #[derive(Debug, Serialize, Deserialize)]
      struct MyData {
          #[serde_as(as = "Option<bson::DateTime>")
          date: Option<chrono::DateTime<Utc>>
      }
      

      And this struct will serialize to / from BSON, even though there's an Option wrapper.

      Originally reported in GH issue: https://github.com/mongodb/bson-rust/issues/303

      Attachments

        Issue Links

          Activity

            People

              patrick.freed@mongodb.com Patrick Freed
              patrick.freed@mongodb.com Patrick Freed
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: