Difference between "async || {}" and "|| async {}"?

79 points Quique1222

I'm using mlua and it has a function that you can use to register a rust clousure as a lua function so it can be called from lua.

It has this function with the following signature

pub fn create_async_function<'lua, A, R, F, FR>(&'lua self, func: F) -> Result<Function<'lua>>
    where
        A: FromLuaMulti<'lua>,
        R: IntoLuaMulti<'lua>,
        F: Fn(&'lua Lua, A) -> FR + MaybeSend + 'static,
        FR: Future<Output = Result<R>> + 'lua,

That can be used to create an async function.

I can register one like this

lua.create_async_function(|lua, _: ()| async { ... });

Which works fine. But when I try to switch the async to the other side of the capture group, like this:

lua.create_async_function(async |lua, _: ()| { ... });

It complains with:

`async` non-`move` closures with parameters are not currently supported

Which is quite confusing as I don't really understand the difference.
This extends to the different clousures, like, what's the difference between

async || {}
|| async {
move || async move {}
|| async move {}
move || move {}
...

Can I read about that somewhere?