PageRenderTime 16ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://github.com/jruderman/rust
Rust | 27 lines | 21 code | 5 blank | 1 comment | 3 complexity | 95ee9c10bbcd48bbe4e69f01bd674226 MD5 | raw file
 1
 2
 3
 4// -*- rust -*-
 5fn id<T: copy>(x: T) -> T { return x; }
 6
 7type triple = {x: int, y: int, z: int};
 8
 9fn main() {
10    let mut x = 62;
11    let mut y = 63;
12    let a = 'a';
13    let mut b = 'b';
14    let p: triple = {x: 65, y: 66, z: 67};
15    let mut q: triple = {x: 68, y: 69, z: 70};
16    y = id::<int>(x);
17    log(debug, y);
18    assert (x == y);
19    b = id::<char>(a);
20    log(debug, b);
21    assert (a == b);
22    q = id::<triple>(p);
23    x = p.z;
24    y = q.z;
25    log(debug, y);
26    assert (x == y);
27}