Implementing trait on closures: how to avoid `type parameter not constrained` errors

I'm trying to implement a ToObject trait for FnMut closures, with trait bounds on the closure's arguments and return values:

pub trait ToObject {
    fn to_object(&self) -> crate::Result<Object>;
}

impl<A, R, F> ToObject for F
where
    A: LuaPoppable,
    R: LuaPushable,
    F: FnMut(A) -> crate::Result<R> + 'static,
{
    fn to_object(&self) -> crate::Result<Object> {
        todo!()
    }
}

this won't compile because both A and R are unconstrained by the impl trait, self type or predicates. I can make it work by making the ToObject trait generic:

pub trait ToObject<A, R> {
    fn to_object(&self) -> crate::Result<Object>;
}

impl<A, R, F> ToObject<A, R> for F
where
    A: LuaPoppable,
    R: LuaPushable,
    F: FnMut(A) -> crate::Result<R> + 'static,
{
    fn to_object(&self) -> crate::Result<Object> {
        todo!()
    }
}

but this makes it pretty awkard when implementing the ToObject trait for all other types as I have two unused A and B generics:

impl<A, B> ToObject<A, B> for usize {
    fn to_object(&self) -> crate::Result<Object> {
        todo!()
    }
}

Is there a less awkward solution?

Depending on the wider context, it might be fine to directly implement this as a constructor for Object.

impl Object {
    fn from_closure<A, R, F>(f: F) -> crate::Result<Object>
    where
        A: LuaPoppable,
        R: LuaPushable,
        F: FnMut(A) -> crate::Result<R> + 'static,
    {
        todo!()
    }
}
3 Likes