2014-02-19 18:56:33 -08:00
|
|
|
use std::fmt;
|
|
|
|
|
2013-01-29 11:14:53 -08:00
|
|
|
struct Thingy {
|
2015-03-25 17:06:52 -07:00
|
|
|
x: isize,
|
|
|
|
y: isize
|
2013-01-29 11:14:53 -08:00
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
impl fmt::Debug for Thingy {
|
2014-02-19 18:56:33 -08:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2014-12-20 00:09:35 -08:00
|
|
|
write!(f, "{{ x: {:?}, y: {:?} }}", self.x, self.y)
|
2013-01-29 11:14:53 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PolymorphicThingy<T> {
|
|
|
|
x: T
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
impl<T:fmt::Debug> fmt::Debug for PolymorphicThingy<T> {
|
2014-02-19 18:56:33 -08:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2014-12-20 00:09:35 -08:00
|
|
|
write!(f, "{:?}", self.x)
|
2013-01-29 11:14:53 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2014-12-20 00:09:35 -08:00
|
|
|
println!("{:?}", Thingy { x: 1, y: 2 });
|
|
|
|
println!("{:?}", PolymorphicThingy { x: Thingy { x: 1, y: 2 } });
|
2013-01-29 11:14:53 -08:00
|
|
|
}
|