// 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 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. struct Pair { a: A, b: B } struct RecEnum(Rec); struct Rec { val: A, rec: Option<@mut RecEnum> } fn make_cycle(a: A) { let g: @mut RecEnum = @mut RecEnum(Rec {val: a, rec: None}); g.rec = Some(g); } struct Invoker { a: A, b: B, } trait Invokable { fn f(&self) -> (A, B); } impl Invokable for Invoker { fn f(&self) -> (A, B) { (self.a.clone(), self.b.clone()) } } fn f( a: A, b: B) -> @Invokable { @Invoker { a: a, b: b, } as @Invokable } pub fn main() { let x = 22_u8; let y = 44_u64; let z = f(~x, y); make_cycle(z); let (a, b) = z.f(); info!("a={} b={}", *a as uint, b as uint); assert_eq!(*a, x); assert_eq!(b, y); }