Closed sunjay closed 4 years ago
impl Debug for Turtle {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
let state = self.window.borrow().fetch_turtle();
Debug::fmt(&state, fmt)
}
}
is this anything
That would be a start, but I'd like to avoid leaking internal implementation details like Pen
and Radians
. It also doesn't accomplish the goal of printing out the unit with the right angle based on how the turtle is configured. That's going to be important as some users of turtle will switch to radians for their particular drawing. If another user or library author assumes degrees, they may have to debug what's going on using this output.
I am probably going to wait to add this until later because the Turtle crate is currently going through some big architectural changes that will effect how this is implemented.
Thank you for your suggestion though! I appreciate the thought. :smile:
We should consider implementing the Debug trait for the Turtle struct so that it becomes possible to print out the turtle and immediately see information about it. It wouldn't be useful to just derive the trait automatically because the Turtle struct doesn't actually directly contain any real information about itself. All of that is in the separate renderer process.
This implementation will probably not be added anytime soon because querying each individual property would just be horrendously slow. Eventually, once we add some low overhead ways to access the other process's memory, we will be able to do this in a reasonably performant way.
The implementation should print out as if the turtle struct actually had all of these fields as normal fields:
pen
that printsPen { thickness: ... }
We can use the methods on the
Formatter
struct that specifically allow for printing structs. Basically we want to totally fake the internal representation just for the sake of making debugging easy.While this issue is specific to the turtle struct, this may be applicable to other types in the crate as well.