2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
2012-09-19 15:59:44 -05:00
|
|
|
// xfail-fast
|
2012-09-18 17:52:21 -05:00
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() { test05(); }
|
2011-12-15 20:44:13 -06:00
|
|
|
|
2013-01-26 00:46:32 -06:00
|
|
|
struct Pair<A,B> { a: A, b: B }
|
2011-12-15 20:44:13 -06:00
|
|
|
|
2013-02-20 19:07:17 -06:00
|
|
|
fn make_generic_record<A:Copy,B:Copy>(a: A, b: B) -> Pair<A,B> {
|
2013-01-26 00:46:32 -06:00
|
|
|
return Pair {a: a, b: b};
|
2011-12-15 20:44:13 -06:00
|
|
|
}
|
|
|
|
|
2013-02-21 21:10:33 -06:00
|
|
|
fn test05_start(f: &~fn(v: float, v: ~str) -> Pair<float, ~str>) {
|
|
|
|
let p = (*f)(22.22f, ~"Hi");
|
2012-12-05 18:51:32 -06:00
|
|
|
log(debug, copy p);
|
2013-03-06 15:58:02 -06:00
|
|
|
fail_unless!(p.a == 22.22f);
|
|
|
|
fail_unless!(p.b == ~"Hi");
|
2011-12-15 20:44:13 -06:00
|
|
|
|
2013-02-21 21:10:33 -06:00
|
|
|
let q = (*f)(44.44f, ~"Ho");
|
2012-12-05 18:51:32 -06:00
|
|
|
log(debug, copy q);
|
2013-03-06 15:58:02 -06:00
|
|
|
fail_unless!(q.a == 44.44f);
|
|
|
|
fail_unless!(q.b == ~"Ho");
|
2011-12-15 20:44:13 -06:00
|
|
|
}
|
|
|
|
|
2013-02-21 21:10:33 -06:00
|
|
|
fn spawn<A:Copy,B:Copy>(f: extern fn(&~fn(A,B)->Pair<A,B>)) {
|
2013-03-01 17:55:31 -06:00
|
|
|
let arg: ~fn(A, B) -> Pair<A,B> = |a, b| make_generic_record(a, b);
|
|
|
|
task::spawn(|| f(&arg));
|
2011-12-15 20:44:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test05() {
|
2012-07-14 00:57:48 -05:00
|
|
|
spawn::<float,~str>(test05_start);
|
2011-12-15 20:44:13 -06:00
|
|
|
}
|