Explanation of function trait bounds on thread::spawn()

I'm especially interested in the second bound on F. I'm struggling to find any explanation in the book and reference of why a parameter would appear twice following where. Why doesn't this definition use two +'s? Is FnOnce also a trait here?

pub fn spawn<F, T>(f: F) -> JoinHandle<T> 
    where F: FnOnce() -> T, F: Send + 'static, T: Send + 'static
1 Like

FnOnce is indeed a trait. FnOnce() -> T is syntactic sugar for FnOnce<(), T>. Not sure why F is listed twice in that list, but it might make things a bit easier to read since FnOnce() -> T + Send + 'static is a bit harder to visually parse.

2 Likes

Thanks! From this I will assume there's no way for a bound not to apply if it appears, so I should treat them all the same no matter what syntax they use.

I'll read up on closures some more to work out exactly what the effect of each of these bounds is.