Last active
August 29, 2015 14:02
-
-
Save kenpratt/68cf998bed99cbc77d89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn generate() -> &str { | |
let s = format!("meaning of life: {}", 42); | |
s.as_slice() | |
} | |
fn main() { | |
println!("{}", generate()); | |
} | |
/* | |
create_str_from_format.rs:3:5: 3:6 error: `s` does not live long enough | |
create_str_from_format.rs:3 s.as_slice() | |
^ | |
create_str_from_format.rs:1:23: 4:2 note: reference must be valid for the anonymous lifetime #1 defined on the block at 1:22... | |
create_str_from_format.rs:1 fn generate() -> &str { | |
create_str_from_format.rs:2 let s = format!("meaning of life: {}", 42); | |
create_str_from_format.rs:3 s.as_slice() | |
create_str_from_format.rs:4 } | |
create_str_from_format.rs:1:23: 4:2 note: ...but borrowed value is only valid for the block at 1:22 | |
create_str_from_format.rs:1 fn generate() -> &str { | |
create_str_from_format.rs:2 let s = format!("meaning of life: {}", 42); | |
create_str_from_format.rs:3 s.as_slice() | |
create_str_from_format.rs:4 } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment