3 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
4 // file at the top-level directory of this distribution and at
5 // http://rust-lang.org/COPYRIGHT.
7 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 // option. This file may not be copied, modified, or distributed
11 // except according to those terms.
13 // Tests that a heterogeneous list of existential types can be put inside an Arc
14 // and shared between tasks as long as all types fulfill Freeze+Send.
24 fn name(&self, blk: |&str|);
25 fn num_legs(&self) -> uint;
26 fn of_good_pedigree(&self) -> bool;
46 fn name(&self, blk: |&str|) { blk(self.name) }
47 fn num_legs(&self) -> uint { 4 }
48 fn of_good_pedigree(&self) -> bool { self.num_whiskers >= 4 }
51 fn name(&self, blk: |&str|) { blk(self.name) }
52 fn num_legs(&self) -> uint { 4 }
53 fn of_good_pedigree(&self) -> bool {
54 self.bark_decibels < 70 || self.tricks_known > 20
57 impl Pet for Goldfyshe {
58 fn name(&self, blk: |&str|) { blk(self.name) }
59 fn num_legs(&self) -> uint { 0 }
60 fn of_good_pedigree(&self) -> bool { self.swim_speed >= 500 }
64 let catte = Catte { num_whiskers: 7, name: ~"alonzo_church" };
65 let dogge1 = Dogge { bark_decibels: 100, tricks_known: 42, name: ~"alan_turing" };
66 let dogge2 = Dogge { bark_decibels: 55, tricks_known: 11, name: ~"albert_einstein" };
67 let fishe = Goldfyshe { swim_speed: 998, name: ~"alec_guinness" };
68 let arc = Arc::new(vec!(~catte as ~Pet:Share+Send,
69 ~dogge1 as ~Pet:Share+Send,
70 ~fishe as ~Pet:Share+Send,
71 ~dogge2 as ~Pet:Share+Send));
72 let (tx1, rx1) = channel();
73 let arc1 = arc.clone();
74 task::spawn(proc() { check_legs(arc1); tx1.send(()); });
75 let (tx2, rx2) = channel();
76 let arc2 = arc.clone();
77 task::spawn(proc() { check_names(arc2); tx2.send(()); });
78 let (tx3, rx3) = channel();
79 let arc3 = arc.clone();
80 task::spawn(proc() { check_pedigree(arc3); tx3.send(()); });
86 fn check_legs(arc: Arc<Vec<~Pet:Share+Send>>) {
88 for pet in arc.get().iter() {
89 legs += pet.num_legs();
94 fn check_names(arc: Arc<~[~Pet:Share+Send]>) {
96 fn check_names(arc: Arc<Vec<~Pet:Freeze+Send> >) {
97 >>>>>>> test: Automatically remove all `~[T]` from tests.
98 for pet in arc.get().iter() {
100 assert!(name[0] == 'a' as u8 && name[1] == 'l' as u8);
105 fn check_pedigree(arc: Arc<~[~Pet:Share+Send]>) {
107 fn check_pedigree(arc: Arc<Vec<~Pet:Freeze+Send> >) {
108 >>>>>>> test: Automatically remove all `~[T]` from tests.
109 for pet in arc.get().iter() {
110 assert!(pet.of_good_pedigree());