What is required to address this lifetime issue with clap?

Hi,

Consider the following code is fine.

    Command::new("name")
        .version("1")
        .about("my about")

I am trying to use the obfstr crate:

This sort of thing works perfectly fine:

    println!(
        "\n#{}!\n",
        obfstr!("Information!"),
    );

However attempting to do this in the clap in the initial example:

        .about(obstr!("My string which is in the about.\n"))

Dies with this:

    |                creates a temporary which is freed while still in use
    |                cast requires that borrow lasts for `'static`

As far as I can work out, it's just a &str both before and after the macro, I can't work out why println! takes input that's so different to clap's about() or .help() which has the same issue, and I've tried variations of making a variable and calling clone() without being able to get around the inability to use this. Any assistance appreciated.

I haven't heard of the crate before and the documentation isn't entirely clear about its limitations.

But it looks like you can create a String from it which will work for you:

Command::new("name")
    .version("1")
    .about(String::from(obfstr!("my about")))

or

Command::new("name")
    .version("1")
    .about(obfstr!("my about").to_string())

Unbelievable, I had tried that second option and it didn't work. The first one however, whilst again looks to be the same, has resolved it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.