As far as I understand this is not doable today. But what exactly is blocking this, and do we have anything in the works that would enable us to compile code like this?
This would mean implementing Debug on types whose inner types are not necessarily Debug, but are external to the application sooo much easier.
Specialization is a helpful feature, however I don't think it helps if there are multiple fields which may or may not be Debug, and even if it does, it presents a source of code duplication and an 2^N problem of implementations.
struct Foo<T, U> {
a: u32,
b: T,
c: U,
}
impl<T: Debug,U> fmt::Debug for Foo<T,U> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let ret = f.debug_struct("Point");
let ret = r.field("a", &self.a);
let ret = r.field("b", &self.b);
#[if_satisfied(G: Debug)]
let ret = r.field("c", &self.c);
#[else]
let ret = r.field("c", "<opaque>");
#[end]
ret.finish()
}
}