Functions can only return a specific type, not traits. Generic functions are the same, except that their return type and parameter type can only be determined when they are called.
Your example:
is correct. Its meaning is: F is a closure. Its return type is S. The concrete type of S can only be determined when handle is called, but the restriction is that S must implement the Future trait.
@keepsimple1 FWIW, this is the reason I prefer to put marker traits and lifetime bounds before the Fn… or in a separate line; it makes everything more readable:
fn handle<F>(&self, handler: F)
where
F : Fn(Request) -> Response,
F : Send + 'static,
Yes it is. That’s why I’m saying you can’t call those functions. As far as I understand, trait bounds on associated types are checked when the trait is implemented, not when the trait is used in a bound somewhere. This is different from type parameters for the trait.
Then there’s also builtin types that don’t really have a proper trait implementation anywhere where the compiler makes them implement the trait somewhat on-the-fly as far as I can tell. For example Fn is implemented by dyn Fn(…) -> … trait objects and by closures and functions and function pointers; all built-in types. These builtin types then need to come with special checks of their own to make sure that their “fake”/on-the-fly trait implementation doesn’t violate any requirements such as that FnOnce::Output: Sized. Sometimes they don’t actually come with such checks, for this particular case, here’s a bug report (by myself) of such an example.