Why is that these 2 work:
fn apply_once1<F: FnOnce(T1) -> T2, T1, T2> (f: F, x: T1) -> T2 { f(x) } fn apply_once2<F, T1, T2> (f: F, x: T1) -> T2 where F: FnOnce(T1) -> T2 { f(x) } But this one doesn't compile:
fn apply_once3<T1, T2> (f: FnOnce(T1) -> T2, x: T1) -> T2 { f(x) } It complains of:
error: the trait `core::marker::Sized` is not implemented for the type `core::ops::FnOnce(T1) -> T2 + 'static` [E0277] once3<T1, T2> (f: FnOnce(T1) -> T2, x: T1) -> T2 { ^ help: see the detailed explanation for E0277 note: `core::ops::FnOnce(T1) -> T2 + 'static` does not have a constant size known at compile-time note: all local variables must have a statically known size I understand that FnOnce might not have statically known size, so normally I would fix that with & swapping the variable for a reference instead, so the size is now known. But I don't understand why apply_once1 and apply_once2 can get away with it?
Searching around, I can't find anything that talks about the difference between putting a trait bound on the argument versus putting it on the type variables.