So at the moment, you can do something like
struct Opaque {
inner1: u32,
inner2: OpaqueObject
}
impl Debug for Opaque {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.debug_struct("Opaque")
.field("inner1", self.inner1)
.finish();
}
}
and get e.g.
Opaque { inner1: 8 }
but this does not tell the reader that there are other fields on Opaque.
It would be possible to show this with a new method non_exhaustive
function on that you would use like
impl Debug for Opaque {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.debug_struct("Opaque")
.field("inner1", self.inner1)
.non_exhaustive()
.finish();
}
}
which would output
Opaque { inner1: 8, .. }
thereby telling the reader that there are more fields that are not representable.
We could also add a method like opaque_field
that would look like
impl Debug for Opaque {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.debug_struct("Opaque")
.field("inner1", self.inner1)
.opaque_field("inner2")
.finish();
}
}
and output
Opaque { field1: 8, field2: <opaque> }
where the string <opaque>
is bikesheddable (e.g. ..
).