Skip to content

Instantly share code, notes, and snippets.

@jamii
Created March 3, 2015 21:32
Show Gist options
  • Save jamii/ddfd591c752ba5332403 to your computer and use it in GitHub Desktop.
Save jamii/ddfd591c752ba5332403 to your computer and use it in GitHub Desktop.
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