It is really possible. One option is to explicitly implement A for reference types:
impl<'a, T: A + ?Sized> A for &'a T {}
The argument becomes a sign of the T = &A object, but at the same time it is a static dispatch for well-known developers of A The following code should now compile:
fn foo<T: A>(a: T) {} struct MyA; impl A for MyA {} fn main() { foo(MyA{}); foo(&MyA{}); foo(&MyA{} as &A); }
If you are ready to always pass a leverage argument, you can also do this:
fn foo<T: A + ?Sized>(a: &T) {}
The argument becomes a feature of the object T = A
source share