expression
Generic worker with Send bounds
A generic worker helper expresses the actual crossing requirements on both the closure and result. Keep the constraints at the concurrency boundary rather than adding them to unrelated domain APIs. Expected stdout (not executed): 42 Common mistake: Adding Sync to every generic parameter even when only ownership transfer is needed.
Formal Syntax & Structure
rust syntaxrust
fn run<T: Send + 'static, F: FnOnce() -> T + Send + 'static>(f: F) -> TWorking Example
Example Snippetrust
fn main() { fn run<T: Send + 'static, F: FnOnce() -> T + Send + 'static>(f: F) -> T { std::thread::spawn(f).join().unwrap() } println!("{}", run(|| 21 * 2));}