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
|
#![allow(dead_code)]
#[macro_use]
extern crate derive_more;
#[derive(Unwrap)]
enum Either<TLeft, TRight> {
Left(TLeft),
Right(TRight),
}
#[derive(Unwrap)]
enum Maybe<T> {
Nothing,
Just(T),
}
#[derive(Unwrap)]
enum Color {
RGB(u8, u8, u8),
CMYK(u8, u8, u8, u8),
}
#[derive(Unwrap)]
enum Nonsense<'a, T> {
Ref(&'a T),
NoRef,
#[unwrap(ignore)]
NoRefIgnored,
}
#[derive(Unwrap)]
enum WithConstraints<T>
where
T: Copy,
{
One(T),
Two,
}
#[derive(Unwrap)]
enum KitchenSink<'a, 'b, T1: Copy, T2: Clone>
where
T2: Into<T1> + 'b,
{
Left(&'a T1),
Right(&'b T2),
OwnBoth(T1, T2),
Empty,
NeverMind(),
NothingToSeeHere(),
}
#[test]
pub fn test_unwrap() {
assert_eq!(Maybe::<()>::Nothing.unwrap_nothing(), ());
}
#[test]
#[should_panic]
pub fn test_unwrap_panic() {
Maybe::<()>::Nothing.unwrap_just()
}
|