File tree Expand file tree Collapse file tree 3 files changed +88
-1
lines changed Expand file tree Collapse file tree 3 files changed +88
-1
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 802deac3233d91bcd6ba5a87c6a4de8b3e12425e
2
+ refs/heads/master: c1092fb6d88efe51e42df3aae2a321cc669e12a0
Original file line number Diff line number Diff line change
1
+ /*
2
+ Module: result
3
+
4
+ A type representing either success or failure
5
+ */
6
+
7
+ /* Section: Types */
8
+
9
+ /*
10
+ Tag: t
11
+
12
+ The result type
13
+ */
14
+ tag t<T , U > {
15
+ /*
16
+ Variant: ok
17
+
18
+ Contains the result value
19
+ */
20
+ ok ( T ) ;
21
+ /*
22
+ Variant: error
23
+
24
+ Contains the error value
25
+ */
26
+ error ( U ) ;
27
+ }
28
+
29
+ /* Section: Operations */
30
+
31
+ /*
32
+ Function: get
33
+
34
+ Get the value out of a successful result
35
+
36
+ Failure:
37
+
38
+ If the result is an error
39
+ */
40
+ fn get < T , U > ( res : t < T , U > ) -> T {
41
+ alt res {
42
+ ok( t) { t }
43
+ error ( _) {
44
+ fail "get called on error result" ;
45
+ }
46
+ }
47
+ }
48
+
49
+ /*
50
+ Function: get
51
+
52
+ Get the value out of an error result
53
+
54
+ Failure:
55
+
56
+ If the result is not an error
57
+ */
58
+ fn get_error < T , U > ( res : t < T , U > ) -> U {
59
+ alt res {
60
+ error( u) { u }
61
+ ok ( _) {
62
+ fail "get_error called on ok result" ;
63
+ }
64
+ }
65
+ }
66
+
67
+ /*
68
+ Function: success
69
+
70
+ Returns true if the result is <ok>
71
+ */
72
+ fn success < T , U > ( res : t < T , U > ) -> bool {
73
+ alt res {
74
+ ok( _) { true }
75
+ error ( _) { false }
76
+ }
77
+ }
78
+
79
+ /*
80
+ Function: failure
81
+
82
+ Returns true if the result is <error>
83
+ */
84
+ fn failure < T , U > ( res : t < T , U > ) -> bool {
85
+ !success ( res)
86
+ }
Original file line number Diff line number Diff line change @@ -97,6 +97,7 @@ mod test;
97
97
mod unsafe;
98
98
mod term;
99
99
mod math;
100
+ mod result;
100
101
101
102
#[cfg(unicode)]
102
103
mod unicode;
You can’t perform that action at this time.
0 commit comments