rust/src/test/run-pass/generic-fn.rs

28 lines
480 B
Rust
Raw Normal View History

2010-06-24 04:03:09 +00:00
// -*- rust -*-
fn id<T: copy>(x: T) -> T { ret x; }
2010-06-24 04:03:09 +00:00
2011-07-27 12:19:39 +00:00
type triple = {x: int, y: int, z: int};
2010-06-24 04:03:09 +00:00
fn main() {
2011-07-27 12:19:39 +00:00
let x = 62;
let y = 63;
let a = 'a';
let b = 'b';
let p: triple = {x: 65, y: 66, z: 67};
let q: triple = {x: 68, y: 69, z: 70};
y = id::<int>(x);
log(debug, y);
assert (x == y);
b = id::<char>(a);
log(debug, b);
assert (a == b);
q = id::<triple>(p);
x = p.z;
y = q.z;
log(debug, y);
assert (x == y);
}