We can already use macros for a "dummy implementation" of an expression:
fn do_something_complex() -> T {
todo!()
}
Now and again I've wanted a "dummy trait object". So:
trait T {
type Q;
fn ask(q: &Q) -> bool;
}
struct S;
dummy_impl!(T<Q = ()> for S);
// generates:
// impl T for S {
// type Q = ();
// fn ask(q: &Q) -> bool { todo!() }
// }
Here we specify Q = ()
; in this example it is not strictly necessary but in cases where the associated type has trait bounds it may be.
The biggest issue: macros can't do this due to lack of introspection for the trait T
(even with proc-macros).
So, questions:
- is such a thing possible with compiler built-ins?
- is it desirable enough to be worth it?
- should it be exposed in
std
?
Motivation:
- writing tests on bounded generic functions may require a concrete type
- writing the impl by hand can be tedious, especially if the trait is frequently modified