add lifecycle str

This commit is contained in:
2020-05-16 00:40:26 +08:00
parent ce657011e8
commit 489463ef84

View File

@@ -0,0 +1,12 @@
fn main() {
let a = string_to_a_str(&"hello world!");
println!("{}", a);
}
// SAFE? may these codes cause memory leak?
fn string_to_a_str(s: &str) -> &'static str {
Box::leak(s.to_owned().into_boxed_str())
}