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

Move trait bounds to implementation instead of Collection struct

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.0.0-beta.2
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Right now, we currently include trait bounds on the type that Collection is generic over at the struct level. However, we could consider moving these bounds to the implementation blocks instead. This would enable finer tuned restrictions over the functionality that a collection is capable of.

      For instance, if a user want to perform a find with a projection, the type that models that projected output would need to be both Serialize and Deserialize, though it's only used for reading and would never be inserted directly into the db. If we instead gated the impl block that contained find and friends only by Deserialize, a user could create a collection over that projected type and would only need to implement Deserialize on the type. Similarly, for write-only situations, users would only need to implement Serialize on their type, though this is probably less common.

      This also has the nice side effect of structs that wrap a Collection<T> not having to also inherit its trait bounds.

      Suggested by univerz here: https://github.com/mongodb/mongo-rust-driver/pull/261#issuecomment-858088695

            Assignee:
            isabel.atkinson@mongodb.com Isabel Atkinson
            Reporter:
            patrick.freed@mongodb.com Patrick Freed
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: