How to specify trait bounds on args of `Fn` in type aliases

I'm confused if (and through which syntax) it's possible to assign trait bounds to arguments of a Fn closure inside a type alias.

I'm trying to define the following

pub type LuaFn = Box<
    dyn 'static
        + Send
        // Doesn't work.
        + for<'lua> Fn<Args: ToLuaMulti<'lua>>(&'lua Lua, Args) -> mlua::Result<()>,
>;

where Lua is a struct and ToLuaMulti is a trait. This also doesn't work

pub type LuaFn = Box<
    dyn 'static
        + Send
        + for<'lua> Fn(&'lua Lua, impl ToLuaMulti<'lua>) -> mlua::Result<()>,
>;

This works but it's not what I'm trying to do: LuaFn shouldn't be generic and Args should implement ToLuaMulti:

pub type LuaFn<Args> = Box<
    dyn 'static + Send + for<'lua> Fn(&'lua Lua, Args) -> mlua::Result<()>,
>;

This is fundamentally impossible. LuaFn has to be generic, or you could pass a dyn ToLuaMulti<'lua> if ToluaMulti is object safe.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.