3 #![allow(non_camel_case_types)]
4 #![allow(non_upper_case_globals)]
6 static tau: f64 = 2.0*3.14159265358979323;
8 struct Point {x: f64, y: f64}
9 struct Size {w: f64, h: f64}
12 rectangle(Point, Size)
16 fn compute_area(shape: &shape) -> f64 {
18 shape::circle(_, radius) => 0.5 * tau * radius * radius,
19 shape::rectangle(_, ref size) => size.w * size.h
24 // self is in the implicit self region
25 pub fn select<'r, T>(&self, threshold: f64, a: &'r T, b: &'r T)
27 if compute_area(self) > threshold {a} else {b}
31 fn select_based_on_unit_circle<'r, T>(
32 threshold: f64, a: &'r T, b: &'r T) -> &'r T {
34 let shape = &shape::circle(Point{x: 0.0, y: 0.0}, 1.0);
35 shape.select(threshold, a, b)
48 fn thing(x: A) -> thing {
55 pub fn bar(self: Box<thing>) -> isize { self.x.a }
56 pub fn quux(&self) -> isize { self.x.a }
57 pub fn baz<'a>(&'a self) -> &'a A { &self.x }
58 pub fn spam(self) -> isize { self.x.a }
61 trait Nus { fn f(&self); }
62 impl Nus for thing { fn f(&self) {} }
65 let y: Box<_> = Box::new(thing(A {a: 10}));
66 assert_eq!(y.clone().bar(), 10);
67 assert_eq!(y.quux(), 10);
69 let z = thing(A {a: 11});
70 assert_eq!(z.spam(), 11);