summaryrefslogtreecommitdiffstats
path: root/third_party/rust/derive_more/tests/is_variant.rs
blob: 10876a40b38f4f7cb938f05954f9ea933654c765 (plain)
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
#![allow(dead_code)]

#[macro_use]
extern crate derive_more;

#[derive(IsVariant)]
enum Either<TLeft, TRight> {
    Left(TLeft),
    Right(TRight),
}

#[derive(IsVariant)]
enum Maybe<T> {
    Nothing,
    Just(T),
}

#[derive(IsVariant)]
enum Color {
    RGB(u8, u8, u8),
    CMYK { c: u8, m: u8, y: u8, k: u8 },
}

#[derive(IsVariant)]
enum Nonsense<'a, T> {
    Ref(&'a T),
    NoRef,
    #[is_variant(ignore)]
    NoRefIgnored,
}

#[derive(IsVariant)]
enum WithConstraints<T>
where
    T: Copy,
{
    One(T),
    Two,
}
#[derive(IsVariant)]
enum KitchenSink<'a, 'b, T1: Copy, T2: Clone>
where
    T2: Into<T1> + 'b,
{
    Left(&'a T1),
    Right(&'b T2),
    OwnBoth { left: T1, right: T2 },
    Empty,
    NeverMind(),
    NothingToSeeHere {},
}

#[test]
pub fn test_is_variant() {
    assert!(Maybe::<()>::Nothing.is_nothing());
    assert!(!Maybe::<()>::Nothing.is_just());
}