I'm sorry, it's probably was answered a lot of times, but I can't google it for some reason. Here's what I'm trying to do.
struct S<'a>(&'a str);
impl<'a> S<'a> {
fn new() -> Self {
let s = format!("foo");
S(&s) // returns a value referencing data owned by the current function
}
}
I understand that as new
owns s
it's borrow can't be returned. It would work with a static string if I remove format!
, but what to do if the string should be generated at runtime?