File: bindings-runpass-2.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (31 lines) | stat: -rw-r--r-- 880 bytes parent folder | download | duplicates (3)
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);
}