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

Prefer returning copies to references

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

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

              Created:
              Updated:
              None
              None
              None
              None