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.
|
|
|
|
|
2013-10-23 03:49:18 -05:00
|
|
|
#[feature(managed_boxes)];
|
|
|
|
|
2013-01-26 00:46:32 -06:00
|
|
|
struct Pair<A,B> {
|
2012-01-18 17:42:00 -06:00
|
|
|
a: A, b: B
|
2013-01-26 00:46:32 -06:00
|
|
|
}
|
2012-01-18 17:42:00 -06:00
|
|
|
|
2013-03-07 18:36:30 -06:00
|
|
|
struct RecEnum<A>(Rec<A>);
|
2013-01-26 00:46:32 -06:00
|
|
|
struct Rec<A> {
|
2012-01-19 12:21:42 -06:00
|
|
|
val: A,
|
2013-02-22 18:08:16 -06:00
|
|
|
rec: Option<@mut RecEnum<A>>
|
2013-01-26 00:46:32 -06:00
|
|
|
}
|
2012-01-19 12:21:42 -06:00
|
|
|
|
2013-07-18 19:12:46 -05:00
|
|
|
fn make_cycle<A:'static>(a: A) {
|
2013-02-22 18:08:16 -06:00
|
|
|
let g: @mut RecEnum<A> = @mut RecEnum(Rec {val: a, rec: None});
|
2012-08-20 14:23:37 -05:00
|
|
|
g.rec = Some(g);
|
2012-01-19 12:21:42 -06:00
|
|
|
}
|
|
|
|
|
2013-09-17 01:37:54 -05:00
|
|
|
struct Invoker<A,B> {
|
|
|
|
a: A,
|
|
|
|
b: B,
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Invokable<A,B> {
|
|
|
|
fn f(&self) -> (A, B);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<A:Clone,B:Clone> Invokable<A,B> for Invoker<A,B> {
|
|
|
|
fn f(&self) -> (A, B) {
|
|
|
|
(self.a.clone(), self.b.clone())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 19:12:46 -05:00
|
|
|
fn f<A:Send + Clone + 'static,
|
|
|
|
B:Send + Clone + 'static>(
|
|
|
|
a: A,
|
|
|
|
b: B)
|
2013-09-17 01:37:54 -05:00
|
|
|
-> @Invokable<A,B> {
|
|
|
|
@Invoker {
|
|
|
|
a: a,
|
|
|
|
b: b,
|
|
|
|
} as @Invokable<A,B>
|
2012-01-18 17:42:00 -06:00
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2012-01-18 17:42:00 -06:00
|
|
|
let x = 22_u8;
|
|
|
|
let y = 44_u64;
|
2012-01-19 12:21:42 -06:00
|
|
|
let z = f(~x, y);
|
|
|
|
make_cycle(z);
|
2013-09-17 01:37:54 -05:00
|
|
|
let (a, b) = z.f();
|
2013-10-21 15:08:31 -05:00
|
|
|
info!("a={} b={}", *a as uint, b as uint);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(*a, x);
|
|
|
|
assert_eq!(b, y);
|
2013-02-14 13:47:00 -06:00
|
|
|
}
|