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