File: option.rs

package info (click to toggle)
rust-result-like 0.4.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 124 kB
  • sloc: makefile: 2
file content (63 lines) | stat: -rw-r--r-- 995 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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use result_like::OptionLike;

#[test]
fn test_generation() {
    #[derive(OptionLike)]
    enum ValueOption {
        Some(i32),
        None,
    }

    assert_eq!(ValueOption::Some(10).into_option(), Some(10));

    #[derive(OptionLike)]
    enum GenericOption<U> {
        Some(U),
        None,
    }

    assert_eq!(GenericOption::Some("x").into_option(), Some("x"));

    struct X;

    #[derive(OptionLike)]
    enum BareOption {
        Some(X),
        None,
    }
}

#[test]
fn test_xo() {
    #[derive(OptionLike)]
    enum XOption<T> {
        Some(T),
        None,
    }

    let xo = XOption::Some(1);

    assert!(xo.unwrap() == 1);

    let op = xo.into_option();

    assert!(op == Some(1));
}

#[test]
fn test_yo() {
    #[derive(OptionLike, is_macro::Is)]
    enum YOption<T> {
        Tone(T),
        Mome,
    }

    let xo = YOption::Tone("s");

    assert!(xo.is_tone());
    assert!(xo.unwrap() == "s");

    let op = xo.into_option();

    assert!(op == Some("s"));
}