File: bindings-runpass-2.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 934,168 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (31 lines) | stat: -rw-r--r-- 880 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//@ run-pass

fn or_at(x: Result<u32, u32>) -> u32 {
    match x {
        Ok(x @ 4) | Err(x @ (6 | 8)) => x,
        Ok(x @ 1 | x @ 2) => x,
        Err(x @ (0..=10 | 30..=40)) if x % 2 == 0 => x + 100,
        Err(x @ 0..=40) => x + 200,
        _ => 500,
    }
}

fn main() {
    assert_eq!(or_at(Ok(1)), 1);
    assert_eq!(or_at(Ok(2)), 2);
    assert_eq!(or_at(Ok(3)), 500);
    assert_eq!(or_at(Ok(4)), 4);
    assert_eq!(or_at(Ok(5)), 500);
    assert_eq!(or_at(Ok(6)), 500);
    assert_eq!(or_at(Err(1)), 201);
    assert_eq!(or_at(Err(2)), 102);
    assert_eq!(or_at(Err(3)), 203);
    assert_eq!(or_at(Err(4)), 104);
    assert_eq!(or_at(Err(5)), 205);
    assert_eq!(or_at(Err(6)), 6);
    assert_eq!(or_at(Err(7)), 207);
    assert_eq!(or_at(Err(8)), 8);
    assert_eq!(or_at(Err(20)), 220);
    assert_eq!(or_at(Err(34)), 134);
    assert_eq!(or_at(Err(50)), 500);
}