Created
March 3, 2015 21:32
-
-
Save jamii/ddfd591c752ba5332403 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 catch(function: fn(Vec<i64>) -> (), input: Vec<i64>) -> bool { | |
let passed_function = function.clone(); | |
let passed_input = input.clone(); | |
let handle = std::thread::spawn(move || passed_function(passed_input)); | |
handle.join().is_err() | |
} | |
fn catch2<Input: Send + Clone>(function: fn(Input) -> (), input: Input) -> bool { | |
let passed_function = function.clone(); | |
let passed_input = input.clone(); | |
let handle = std::thread::spawn(move || passed_function(passed_input)); | |
handle.join().is_err() | |
} | |
// catch is fine | |
// catch 2 produces: | |
// src/lib.rs:67:42: 67:74 error: the parameter type `Input` may not live long enough [E0310] | |
// src/lib.rs:67 let handle = std::thread::spawn(move || passed_function(passed_input)); | |
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// src/lib.rs:67:42: 67:74 help: consider adding an explicit lifetime bound `Input: 'static`... | |
// src/lib.rs:67 let handle = std::thread::spawn(move || passed_function(passed_input)); | |
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// src/lib.rs:67:42: 67:74 note: ...so that captured variable `passed_input` does not outlive the enclosing closure | |
// src/lib.rs:67 let handle = std::thread::spawn(move || passed_function(passed_input)); | |
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment