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.
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2015-03-30 08:38:27 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2015-03-25 19:06:52 -05:00
|
|
|
struct Point {x: isize, y: isize}
|
2011-08-15 06:39:45 -05:00
|
|
|
|
2013-01-26 00:46:32 -06:00
|
|
|
type rect = (Point, Point);
|
2011-08-15 06:39:45 -05:00
|
|
|
|
2013-01-26 00:46:32 -06:00
|
|
|
fn fst(r: rect) -> Point { let (fst, _) = r; return fst; }
|
|
|
|
fn snd(r: rect) -> Point { let (_, snd) = r; return snd; }
|
2011-08-15 06:39:45 -05:00
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn f(r: rect, x1: isize, y1: isize, x2: isize, y2: isize) {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(fst(r).x, x1);
|
|
|
|
assert_eq!(fst(r).y, y1);
|
|
|
|
assert_eq!(snd(r).x, x2);
|
|
|
|
assert_eq!(snd(r).y, y2);
|
2011-08-15 06:39:45 -05:00
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2013-01-26 00:46:32 -06:00
|
|
|
let r: rect = (Point {x: 10, y: 20}, Point {x: 11, y: 22});
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(fst(r).x, 10);
|
|
|
|
assert_eq!(fst(r).y, 20);
|
|
|
|
assert_eq!(snd(r).x, 11);
|
|
|
|
assert_eq!(snd(r).y, 22);
|
2011-08-15 06:39:45 -05:00
|
|
|
let r2 = r;
|
2015-03-25 19:06:52 -05:00
|
|
|
let x: isize = fst(r2).x;
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(x, 10);
|
2011-08-15 06:39:45 -05:00
|
|
|
f(r, 10, 20, 11, 22);
|
|
|
|
f(r2, 10, 20, 11, 22);
|
|
|
|
}
|