add lifecycle str
This commit is contained in:
12
single_file_tests/lifecycle_str.rs
Normal file
12
single_file_tests/lifecycle_str.rs
Normal 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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user