I'd like to create a type alias to promote closures to functions without the user having to think about the parameter and return signatures of their functions. This would translate this bit of code:
async fn some_func(s: &mut Context<Props>) -> VNode {
// some function body...
}
into this bit of code:
static SomeFunc: FC<Props> = |ctx| async {
// some function body
};
In JavaScript, this would use the const closure function definition over the regular function shorthand.
For regular functions, this works fine:
type FC<T: Props> = fn(&mut Context<T>) -> Vnode;
Then, static closures are promoted to function pointers.
However, impl Future
cannot be used in a type alias (not even on 1.51 nightly), and I can't have generic trait bounds in type aliases either. I can't tell if this is possible, but am curious if there are ways for a type alias to work for async fns.
Why?
The API I'm designing takes functions as inputs (not structs or trait objects) and I'd like to make it easy to work with.