hubcaps icon indicating copy to clipboard operation
hubcaps copied to clipboard

IssueOptions::new doesn't take `None` for Assignee's

Open Arzte opened this issue 7 years ago • 4 comments

When attempting to provide None for Assignee, you get a compilation error since None can't be converted into a String

error[E0283]: type annotations required: cannot resolve `_: std::convert::Into<std::string::String>`
  --> src/main.rs:30:22
   |
30 |             .create(&IssueOptions::new(
   |                      ^^^^^^^^^^^^^^^^^
   |
   = note: required by `hubcaps::issues::IssueOptions::new`

Example code causing this error:

github.repo("softprops", "hubcaps")
      .issues()
      .create(&IssueOptions::new(
              "test issue",
              Some("What The Title Says"),
              None,
              None,
              vec!["bug"],
       ))

This conversion should be skipped if assignees is provided as None

Arzte avatar Dec 02 '17 13:12 Arzte

I'll take a closer look this weekend

softprops avatar Dec 02 '17 19:12 softprops

Realizing now this is kind of a crappy interface for type inference because the compiler can't infer much implicitly from None types with out a bit more explicit info. You can work around this with the following type ascriptions

github.repo("softprops", "hubcaps").issues().create(
                &IssueOptions::new::<_, &str, &str, _>(
                    "test issue",
                    Some("What The Title Says"),
                    None,
                    None,
                    vec!["bug"],
                ),
            );

I'm going to think about about a better design

softprops avatar Dec 04 '17 04:12 softprops

Thanks for the update!

Arzte avatar Dec 04 '17 12:12 Arzte

Alternative versions

// #1
let assignee: Option<String> = None;
IssueOptions::new(
    "test issue",
    Some("What The Title Says"),
    assignee,
    None,
    vec!["bug"],
);

// #2
IssueOptions::new(
    "test issue",
    Some("What The Title Says"),
    None::<String>,
    None,
    vec!["bug"],
);

nickelc avatar Jun 19 '18 20:06 nickelc