2013-06-17 19:23:18 -05:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
2013-05-06 10:32:34 -05:00
|
|
|
// 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-19 20:56:33 -06:00
|
|
|
use std::fmt;
|
|
|
|
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Show)]
|
2013-06-17 19:23:18 -05:00
|
|
|
enum A {}
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Show)]
|
2013-06-17 19:23:18 -05:00
|
|
|
enum B { B1, B2, B3 }
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Show)]
|
2014-05-22 18:57:53 -05:00
|
|
|
enum C { C1(int), C2(B), C3(String) }
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Show)]
|
2013-06-17 19:23:18 -05:00
|
|
|
enum D { D1{ a: int } }
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Show)]
|
2013-06-17 19:23:18 -05:00
|
|
|
struct E;
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Show)]
|
2013-06-17 19:23:18 -05:00
|
|
|
struct F(int);
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Show)]
|
2013-06-17 19:23:18 -05:00
|
|
|
struct G(int, int);
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Show)]
|
2013-06-17 19:23:18 -05:00
|
|
|
struct H { a: int }
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Show)]
|
2013-06-17 19:23:18 -05:00
|
|
|
struct I { a: int, b: int }
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Show)]
|
2013-06-17 19:23:18 -05:00
|
|
|
struct J(Custom);
|
2013-05-24 21:35:29 -05:00
|
|
|
|
2013-06-17 19:23:18 -05:00
|
|
|
struct Custom;
|
2014-02-19 20:56:33 -06:00
|
|
|
impl fmt::Show for Custom {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2014-05-10 16:05:06 -05:00
|
|
|
write!(f, "yay")
|
2014-02-19 20:56:33 -06:00
|
|
|
}
|
2013-05-06 10:32:34 -05:00
|
|
|
}
|
|
|
|
|
2014-12-20 02:09:35 -06:00
|
|
|
trait ToShow {
|
|
|
|
fn to_show(&self) -> String;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: fmt::Show> ToShow for T {
|
|
|
|
fn to_show(&self) -> String {
|
|
|
|
format!("{:?}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-25 02:43:37 -05:00
|
|
|
pub fn main() {
|
2014-12-20 02:09:35 -06:00
|
|
|
assert_eq!(B::B1.to_show(), "B1".to_string());
|
|
|
|
assert_eq!(B::B2.to_show(), "B2".to_string());
|
|
|
|
assert_eq!(C::C1(3).to_show(), "C1(3i)".to_string());
|
|
|
|
assert_eq!(C::C2(B::B2).to_show(), "C2(B2)".to_string());
|
|
|
|
assert_eq!(D::D1{ a: 2 }.to_show(), "D1 { a: 2i }".to_string());
|
|
|
|
assert_eq!(E.to_show(), "E".to_string());
|
|
|
|
assert_eq!(F(3).to_show(), "F(3i)".to_string());
|
|
|
|
assert_eq!(G(3, 4).to_show(), "G(3i, 4i)".to_string());
|
|
|
|
assert_eq!(I{ a: 2, b: 4 }.to_show(), "I { a: 2i, b: 4i }".to_string());
|
|
|
|
assert_eq!(J(Custom).to_show(), "J(yay)".to_string());
|
2013-05-24 21:35:29 -05:00
|
|
|
}
|