Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from_str parser for an Option field #168

Closed
mbrobbel opened this issue Mar 8, 2019 · 5 comments
Closed

from_str parser for an Option field #168

mbrobbel opened this issue Mar 8, 2019 · 5 comments
Labels
bug This is a BUG. The fix may be released in a patch version even if considered breaking

Comments

@mbrobbel
Copy link

mbrobbel commented Mar 8, 2019

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`

It works without the Option or by implementing From<&&str> for A. Is this intended behavior?

rust 1.33 
structopt 0.2.14
@TeXitoi
Copy link
Owner

TeXitoi commented Mar 8, 2019

Looks like a bug.

@TeXitoi TeXitoi added the bug This is a BUG. The fix may be released in a patch version even if considered breaking label Mar 8, 2019
@TeXitoi
Copy link
Owner

TeXitoi commented Mar 8, 2019

Got it.

@TeXitoi TeXitoi closed this as completed in 168f1d4 Mar 8, 2019
@TeXitoi
Copy link
Owner

TeXitoi commented Mar 8, 2019

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

TeXitoi added a commit that referenced this issue Mar 8, 2019
TeXitoi added a commit that referenced this issue Mar 8, 2019
@mbrobbel
Copy link
Author

mbrobbel commented Mar 8, 2019

Thanks for the quick reply and fix!

TeXitoi added a commit that referenced this issue Mar 8, 2019
@TeXitoi
Copy link
Owner

TeXitoi commented Mar 8, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a BUG. The fix may be released in a patch version even if considered breaking
Projects
None yet
Development

No branches or pull requests

2 participants