rust/src/test/run-pass/sendfn-generic-fn.rs

49 lines
1.2 KiB
Rust
Raw Normal View History

// 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.
// xfail-fast
#[legacy_modes];
extern mod std;
2012-12-13 16:18:47 -06:00
use oldcomm::Chan;
use oldcomm::send;
fn main() { test05(); }
type pair<A,B> = { a: A, b: B };
fn make_generic_record<A: Copy, B: Copy>(a: A, b: B) -> pair<A,B> {
2012-08-01 19:30:05 -05:00
return {a: a, b: b};
}
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);
assert p.a == 22.22f;
assert p.b == ~"Hi";
let q = f(44.44f, ~"Ho");
2012-12-05 18:51:32 -06:00
log(debug, copy q);
assert q.a == 44.44f;
assert q.b == ~"Ho";
}
fn spawn<A: Copy, B: Copy>(f: extern fn(fn~(A,B)->pair<A,B>)) {
let arg = fn~(a: A, b: B) -> pair<A,B> {
2012-08-01 19:30:05 -05:00
return make_generic_record(a, b);
};
2012-06-30 18:19:07 -05:00
task::spawn(|| f(arg) );
}
fn test05() {
spawn::<float,~str>(test05_start);
}