EmbarkStudios / mirror-mirror

🪞 Powerful reflection library for Rust
Apache License 2.0
79 stars 2 forks source link

Does `debug()` need to be a method in the `Reflect` trait? #73

Closed bnjbvr closed 1 year ago

bnjbvr commented 1 year ago

I'm looking at the code right now and I'm wondering why there's a separate notion of debug formatting for Reflectables values? What are the benefits compared to letting the type implementing Reflect implement Debug if they want to?

davidpdrsn commented 1 year ago

It's so we can implement Debug for dyn Reflect (https://github.com/EmbarkStudios/mirror-mirror/blob/main/crates/mirror-mirror/src/lib.rs#L577).

We could technically use https://github.com/EmbarkStudios/mirror-mirror/blob/main/crates/mirror-mirror/src/lib.rs#L1283 but using the Debug impl directly from the type will give more precise output, specially if the reflection type uses ReflectRef::Opaque. It might also be slightly faster.

bnjbvr commented 1 year ago

Ok, so Reflect types don't have to provide a Debug implementation, but we can still get a free Debug-like implementation for those types, based on the reflected fields (and in theory, we could add metadata in there, if we wanted to).