3 #![allow(non_camel_case_types)]
4 #![allow(non_upper_case_globals)]
6 #![feature(box_syntax)]
8 static tau: f64 = 2.0*3.14159265358979323;
10 struct Point {x: f64, y: f64}
11 struct Size {w: f64, h: f64}
14 rectangle(Point, Size)
18 fn compute_area(shape: &shape) -> f64 {
20 shape::circle(_, radius) => 0.5 * tau * radius * radius,
21 shape::rectangle(_, ref size) => size.w * size.h
26 // self is in the implicit self region
27 pub fn select<'r, T>(&self, threshold: f64, a: &'r T, b: &'r T)
29 if compute_area(self) > threshold {a} else {b}
33 fn select_based_on_unit_circle<'r, T>(
34 threshold: f64, a: &'r T, b: &'r T) -> &'r T {
36 let shape = &shape::circle(Point{x: 0.0, y: 0.0}, 1.0);
37 shape.select(threshold, a, b)
50 fn thing(x: A) -> thing {
57 pub fn bar(self: Box<thing>) -> isize { self.x.a }
58 pub fn quux(&self) -> isize { self.x.a }
59 pub fn baz<'a>(&'a self) -> &'a A { &self.x }
60 pub fn spam(self) -> isize { self.x.a }
63 trait Nus { fn f(&self); }
64 impl Nus for thing { fn f(&self) {} }
67 let y: Box<_> = box thing(A {a: 10});
68 assert_eq!(y.clone().bar(), 10);
69 assert_eq!(y.quux(), 10);
71 let z = thing(A {a: 11});
72 assert_eq!(z.spam(), 11);