-3

I'm using Rust's structopt crate, but when I try to compile examples I'm getting the following error,

error[E0277]: the trait bound `String: From<&OsStr>` is not satisfied
   --> bin/seq.rs:21:36
    |
21  |     #[structopt(short, long, parse(from_os_str))]
    |                                    ^^^^^^^^^^^ the trait `From<&OsStr>` is not implemented for `String`
    |
    = help: the following implementations were found:
              <String as From<&String>>
              <String as From<&mut str>>
              <String as From<&str>>
              <String as From<Box<str>>>
            and 2 others
note: required by `from`
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
  • 1
    If it's taken out of the examples and doesn't compile, maybe it'd be a good idea to submit an issue to fix (or clarify) the examples in question? A SO post is great, but eliminating the source of the confusion sounds better. – user4815162342 Oct 04 '21 at 07:50
  • @user4815162342 I think It's a typo/failed adaptation on my part. I can't find the original that I thought I copied pasted. Problem was me, still think this will help other people who do the same thing (copy the attributes and change the types in the example). – Evan Carroll Oct 04 '21 at 15:16

1 Answers1

0

You can convert a String into a OsString with an infallible conversion, but you can not convert a OsString into a String.

This is because an OsStr accepts things that are not valid Strings so there is no way to ensure an OsStr that structopt parses into can be converted to a String.

You likely don't need to parse() at all,

#[structopt(short, long)]

Not

#[structopt(short, long, parse(from_os_str))]
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468