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

Incorrect Deserialize requirement on generic type in from_bson

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • bson-1.1.0
    • Affects Version/s: None
    • Component/s: None
    • None

      In from_bson<T>(value: Bson), the T is required to be Deserialize<'de>, which has a lifetime associated with any borrowed values from the input. However, from_bson accepts an owned value, so no borrowing is possible and this lifetime is unused. This can result in situations where the deserialization attempt will compile but will always fail at runtime (e.g. when a borrowed value is part of the struct, see relevant GitHub issue).

      serde_json's equivalent method, from_value, bounds the T on DeserializeOwned instead, and emits compiler errors when structs with borrowed fields are deserialized. Ideally, from_bson should do this as well, though it is likely not possible to enable this without a breaking change.

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

              Created:
              Updated:
              Resolved: