ExportXMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Trivial - P5
    • 4.0.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I noticed the driver takes a vec![StreamAddress] as part of the configuration. This currently looks like this:

      let options = ClientOptions::builder()
                        .hosts(vec![
                            StreamAddress {
                                hostname: "localhost".into(),
                                port: Some(27017),
                            }
                        ])
                        .build();
      
      let client = Client::with_options(options)?;
      

      The core construct here is Vec<StreamAddress>, which is "one or more socket address". Std ships a built-in for this in the form of std::net::ToSocketAddrs which comes with various convenient shorthands including From<(&str, u16)>. I suspect using ToSocketAddrs in the API bound could help simplify the base use:

      // Constructor with a single address
      let options = ClientOptions::builder()
          .hosts("localhost:27017")
          .build();
      let client = Client::with_options(options)?;
      
      // Constructor with multiple addresses, the first available from the list is chosen.
      let options = ClientOptions::builder()
          .hosts(["localhost:27017", "localhost:27018"])
          .build();
      let client = Client::with_options(options)?;
      

      This seems like it could be a nice ergonomics improvement.

            Assignee:
            Unassigned
            Reporter:
            Yoshua Wuyts
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: