-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
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.