Structopt: from_str parser for an Option field

Created on 8 Mar 2019  路  5Comments  路  Source: TeXitoi/structopt

Using a from_str parser for an Option field results in the following:

use structopt::StructOpt;

#[derive(Debug)]
struct A {}

impl From<&str> for A {
    fn from(a: &str) -> A {
        // ...
        A {}
    }
}

#[derive(Debug, StructOpt)]
struct Opt {
    #[structopt(parse(from_str))]
    a: Option<A>,
}
error[E0277]: the trait bound `A: std::convert::From<&&str>` is not satisfied
  --> src/lib.rs:13:17
   |
13 | #[derive(Debug, StructOpt)]
   |                 ^^^^^^^^^ the trait `std::convert::From<&&str>` is not implemented for `A`
   |
   = help: the following implementations were found:
             <A as std::convert::From<&str>>
   = note: required by `std::convert::From::from`



md5-440378ef64ed62d6c91840a8d42e5bfb



rust 1.33 
structopt 0.2.14
bug

Most helpful comment

Got it.

All 5 comments

Looks like a bug.

Got it.

I'll publish v0.2.15 when my email is validated by crates.io (hopefully within 2 hours).

Thanks for the quick reply and fix!

v0.2.15 published. Thanks for reporting, and enjoy!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bestouff picture bestouff  路  6Comments

jackjen picture jackjen  路  7Comments

wez picture wez  路  7Comments

liamdawson picture liamdawson  路  5Comments

epage picture epage  路  7Comments