-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
Rust Drivers
-
None
-
None
-
None
-
None
-
None
-
None
While returning references to internal state is easy, ergonomic, and efficient thanks to Rust's lifetime rules, we've run into situations a few times now where it makes evolving an API surprisingly difficult (most recent: https://github.com/mongodb/mongo-rust-driver/pull/1319). Specifically, returning a reference means there's no way to change the internal representation of that value to a different type; there must always be an owned value of the returned type present.
When we next make a breaking release, we should audit the API for where we're doing that. In some cases efficiency is a high priority and in those cases we'll need to continue handing out references, but in general we should prefer to return owned values so that we have the freedom to change internal representation and convert at the function boundary if necessary.