Skip to content

Instantly share code, notes, and snippets.

@kenpratt
Last active August 29, 2015 14:02
Show Gist options
  • Save kenpratt/68cf998bed99cbc77d89 to your computer and use it in GitHub Desktop.
Save kenpratt/68cf998bed99cbc77d89 to your computer and use it in GitHub Desktop.
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