File: throw.rs

package info (click to toggle)
rust-fehler 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 132 kB
  • sloc: makefile: 4
file content (22 lines) | stat: -rw-r--r-- 387 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use fehler::throw;

#[test]
fn throw_works() {
    fn foo() -> Result<(), i32> { throw!(0) }
    assert_eq!(foo(), Err(0));
}

#[test]
fn throw_infers_ok_type() {
    fn foo(b: bool) -> Result<i32, ()> {
        let x = if b {
            0
        } else {
            throw!(());
        };
        Ok(x)
    }

    assert_eq!(foo(true), Ok(0));
    assert_eq!(foo(false), Err(()));
}