3 #![allow(non_camel_case_types)]
4 #![allow(non_snake_case)]
6 #![feature(box_syntax)]
8 // Example from lkuper's intern talk, August 2012.
9 use Color::{cyan, magenta, yellow, black};
10 use ColorTree::{leaf, branch};
13 fn isEq(&self, a: &Self) -> bool;
16 #[derive(Clone, Copy)]
17 enum Color { cyan, magenta, yellow, black }
19 impl Equal for Color {
20 fn isEq(&self, a: &Color) -> bool {
22 (cyan, cyan) => { true }
23 (magenta, magenta) => { true }
24 (yellow, yellow) => { true }
25 (black, black) => { true }
34 branch(Box<ColorTree>, Box<ColorTree>)
37 impl Equal for ColorTree {
38 fn isEq(&self, a: &ColorTree) -> bool {
40 (&leaf(ref x), &leaf(ref y)) => { x.isEq(&(*y).clone()) }
41 (&branch(ref l1, ref r1), &branch(ref l2, ref r2)) => {
42 (*l1).isEq(&(**l2).clone()) && (*r1).isEq(&(**r2).clone())
50 assert!(cyan.isEq(&cyan));
51 assert!(magenta.isEq(&magenta));
52 assert!(!cyan.isEq(&yellow));
53 assert!(!magenta.isEq(&cyan));
55 assert!(leaf(cyan).isEq(&leaf(cyan)));
56 assert!(!leaf(cyan).isEq(&leaf(yellow)));
58 assert!(branch(box leaf(magenta), box leaf(cyan))
59 .isEq(&branch(box leaf(magenta), box leaf(cyan))));
61 assert!(!branch(box leaf(magenta), box leaf(cyan))
62 .isEq(&branch(box leaf(magenta), box leaf(magenta))));
64 println!("Assertions all succeeded!");