'concat string using format!() and return to &'static str [duplicate]
I'll get error when compiled: 'returns value referencing data owned by the current function'
here's the code:
fn return_static_str(a: &'static str, b: &'static str) -> &'static str {
format!("{} {}", a,b).as_str()
}
fn main() {
let s = return_static_str("Hello ", "World!");
}
using return as_ref()
get same issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|