Created
June 23, 2014 19:06
-
-
Save kenpratt/7ed7809f8d8af9363053 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
#[deriving(Show)] | |
struct SampleError<'a> { | |
message: &'a str | |
} | |
fn generate_err() -> Result<(), SampleError> { | |
let m = format!("sample dynamic error: {}", 42); | |
Err(SampleError { message: m.as_slice() }) | |
} | |
fn main() { | |
println!("{}", generate_err()); | |
} | |
/* | |
string_in_error.rs:8:32: 8:33 error: `m` does not live long enough | |
string_in_error.rs:8 Err(SampleError { message: m.as_slice() }) | |
^ | |
string_in_error.rs:6:46: 9:2 note: reference must be valid for the anonymous lifetime #1 defined on the block at 6:45... | |
string_in_error.rs:6 fn generate_err() -> Result<(), SampleError> { | |
string_in_error.rs:7 let m = format!("sample dynamic error: {}", 42); | |
string_in_error.rs:8 Err(SampleError { message: m.as_slice() }) | |
string_in_error.rs:9 } | |
string_in_error.rs:6:46: 9:2 note: ...but borrowed value is only valid for the block at 6:45 | |
string_in_error.rs:6 fn generate_err() -> Result<(), SampleError> { | |
string_in_error.rs:7 let m = format!("sample dynamic error: {}", 42); | |
string_in_error.rs:8 Err(SampleError { message: m.as_slice() }) | |
string_in_error.rs:9 } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment