2014-02-05 22:33:10 +00:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-02-20 02:56:33 +00:00
|
|
|
use std::fmt;
|
|
|
|
|
2013-01-29 19:14:53 +00:00
|
|
|
struct Thingy {
|
|
|
|
x: int,
|
|
|
|
y: int
|
|
|
|
}
|
|
|
|
|
2014-02-20 02:56:33 +00:00
|
|
|
impl fmt::Show for Thingy {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2014-02-20 02:56:33 +00:00
|
|
|
impl<T:fmt::Show> fmt::Show for PolymorphicThingy<T> {
|
|
|
|
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
|
|
|
}
|