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

Pass String to description #1336

Closed
jmaargh opened this issue Aug 28, 2018 · 2 comments
Closed

Pass String to description #1336

jmaargh opened this issue Aug 28, 2018 · 2 comments

Comments

@jmaargh
Copy link

jmaargh commented Aug 28, 2018

How do I send a heap String to App::description?

Rust Version and Affected Version of clap

Rust 2018 from the playground

Bug Summary

Can't pass a String either by-value or by borrow to about. Error message:

error[E0277]: the trait bound `&str: std::convert::From<&std::string::String>` is not satisfied
  --> src/main.rs:12:34
   |
12 |     let matches = App::new(NAME).about(&description).get_matches();
   |                                  ^^^^^ the trait `std::convert::From<&std::string::String>` is not implemented for `&str`
   |
   = note: required because of the requirements on the impl of `std::convert::Into<&str>` for `&std::string::String`

Sample Code or Link to Sample Code

https://play.rust-lang.org/?gist=15667c16c7d853ce4a668dfb453948b6&version=nightly&mode=debug&edition=2018

@JD557
Copy link

JD557 commented Apr 6, 2019

You can either call as_str:

let matches = App::new(NAME).about(description.as_str()).get_matches();

or use &* (which is now suggested by rustc):

let matches = App::new(NAME).about(&*description).get_matches();

@haoadoreorange
Copy link

haoadoreorange commented Jul 22, 2021

I'm trying to understand why the API use Into<&str> in the first place. Do you have any references ? @JD557
EDIT: @Dylan-DPC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants