Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplementing Display formatter for Rect type. #73
Conversation
We need this for dumping DisplayList geometric information on servo.
| fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | ||
| // Why this won't compile? rustc will say that neither Point2D or | ||
| // Size2D has Debug implemented! | ||
| //write!(f, "Rect(Size {:?} at Origin {:?})", self.size, self.origin) |
This comment has been minimized.
This comment has been minimized.
pcwalton
Mar 16, 2015
Contributor
Can you try Size {} at Origin {}? (or at least that with self.size.to_string() and likewise with origin)
This will allow to have cleaner code in Rect.
|
Implemented the Display operator (previously String op) in both Point and Size to make it work on Rect. |
|
Why do you need it? Wouldn't you be able to use |
|
bjz check servo/servo#5209 |
| @@ -29,6 +29,13 @@ impl<T: fmt::Debug> fmt::Debug for Rect<T> { | |||
| } | |||
| } | |||
|
|
|||
| impl<T: fmt::Display> fmt::Display for Rect<T> { | |||
| fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | |||
| write!(formatter, "Rect(Size {} at Origin {})", self.size.to_string(), self.origin.to_string()); | |||
This comment has been minimized.
This comment has been minimized.
pcwalton
Mar 16, 2015
Contributor
Is there a reason why this follows a different format from Debug? Rect({} at {}) seems terser.
| @@ -26,6 +26,13 @@ impl<T: fmt::Debug> fmt::Debug for Size2D<T> { | |||
| } | |||
| } | |||
|
|
|||
| impl<T: fmt::Display> fmt::Display for Size2D<T> { | |||
| fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | |||
| write!(formatter, "({},{})", self.width, self.height); | |||
This comment has been minimized.
This comment has been minimized.
|
Should be ok now. |
Implementing Display formatter for Rect type.
|
I'm not very invested in this project, but I might suggest reverting this, because it is not needed by servo/servo#5209 |
|
@bjz would elaborate more on it? We have to print the Rect's in BaseDisplayItem (i.e. bounds). The first patch version would directly access Rect fields but that turned out to be quite verbose. That lead to implementing the operators for Rect and its types. |
|
|
Adenilson commentedMar 16, 2015
We need this for dumping DisplayList geometric information on servo.