Lifetime headache: expected named lifetime parameter

i have made a mock up of the code and i get an error with these kindly help

You are returning &str from an async function, but the lifetime won't be long enough. Async functions need lifetimes that outlive the duration of the function.

To avoid further headaches, return an owned type instead (String).

thanks @moy2010 but i need a &str because i use an external lib which receives a &str and not and owned type

Why won't taking a reference to the owned String after it has been returned work?

Also, it isn't clear why your functions need to be async (though that could be due to the simplification for the playground), but you will encounter similar issues with non-async functions.

The function should be:

        pub fn name(&self) -> &str {

fn name(self) passes ownership of self instead of borrowing it, which means "make this the last use of the Application, and won't let it be used again after calling name", which isn't what you want.

Functions that don't use .await are not supposed to be declared as async.

1 Like

have you tried this and working it still not working as expected