Created
May 17, 2018 14:04
-
-
Save jw3126/cc0e75cc8275dede5430ca36917f6be0 to your computer and use it in GitHub Desktop.
temporary value does not live long enough
This file contains hidden or 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
#[derive(Debug)] | |
struct MyString { | |
s:String, | |
} | |
impl MyString { | |
fn to_str(&self) -> &str { | |
&self.s | |
} | |
} | |
fn main() { | |
let s = MyString {s:"1".to_string()}; | |
let t = s.to_str(); | |
// let s2 = MyString {s:"1".to_string()}.to_str(); | |
// does not work. It seems to be equivalent to | |
// let s3 = { | |
// MyString {s:"1".to_string()} | |
// }.to_str(); | |
println!("{:?}", s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment