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