|
20 | 20 | typed(json_boolean) is_ok; \ |
21 | 21 | union { \ |
22 | 22 | typed(name) value; \ |
23 | | - const char *err; \ |
| 23 | + typed(json_string) err; \ |
24 | 24 | } inner; \ |
25 | 25 | } result(name); \ |
26 | 26 | result(name) result_ok(name)(typed(name)); \ |
27 | | - result(name) result_err(name)(const char *); \ |
| 27 | + result(name) result_err(name)(typed(json_string)); \ |
28 | 28 | typed(json_boolean) result_is_ok(name)(result(name) *); \ |
29 | 29 | typed(json_boolean) result_is_err(name)(result(name) *); \ |
30 | 30 | typed(name) result_unwrap(name)(result(name) *); \ |
31 | | - const char *result_unwrap_err(name)(result(name) *); |
| 31 | + typed(json_string) result_unwrap_err(name)(result(name) *); |
32 | 32 |
|
33 | | -#define define_result_type(name) \ |
34 | | - result(name) result_ok(name)(typed(name) value) { \ |
35 | | - result(name) retval = { \ |
36 | | - .is_ok = true, \ |
37 | | - .inner = { \ |
38 | | - .value = value, \ |
39 | | - }, \ |
40 | | - }; \ |
41 | | - return retval; \ |
42 | | - } \ |
43 | | - result(name) result_err(name)(const char *err) { \ |
44 | | - result(name) retval = { \ |
45 | | - .is_ok = false, \ |
46 | | - .inner = { \ |
47 | | - .err = err, \ |
48 | | - }, \ |
49 | | - }; \ |
50 | | - return retval; \ |
51 | | - } \ |
52 | | - json_boolean_t result_is_ok(name)(result(name) * result) { \ |
53 | | - return result->is_ok; \ |
54 | | - } \ |
55 | | - json_boolean_t result_is_err(name)(result(name) * result) { \ |
56 | | - return !result->is_ok; \ |
57 | | - } \ |
58 | | - typed(name) result_unwrap(name)(result(name) * result) { \ |
59 | | - return result->inner.value; \ |
60 | | - } \ |
61 | | - const char *result_unwrap_err(name)(result(name) * result) { \ |
62 | | - return result->inner.err; \ |
| 33 | +#define define_result_type(name) \ |
| 34 | + result(name) result_ok(name)(typed(name) value) { \ |
| 35 | + result(name) retval = { \ |
| 36 | + .is_ok = true, \ |
| 37 | + .inner = { \ |
| 38 | + .value = value, \ |
| 39 | + }, \ |
| 40 | + }; \ |
| 41 | + return retval; \ |
| 42 | + } \ |
| 43 | + result(name) result_err(name)(typed(json_string) err) { \ |
| 44 | + result(name) retval = { \ |
| 45 | + .is_ok = false, \ |
| 46 | + .inner = { \ |
| 47 | + .err = err, \ |
| 48 | + }, \ |
| 49 | + }; \ |
| 50 | + return retval; \ |
| 51 | + } \ |
| 52 | + typed(json_boolean) result_is_ok(name)(result(name) * result) { \ |
| 53 | + return result->is_ok; \ |
| 54 | + } \ |
| 55 | + typed(json_boolean) result_is_err(name)(result(name) * result) { \ |
| 56 | + return !result->is_ok; \ |
| 57 | + } \ |
| 58 | + typed(name) result_unwrap(name)(result(name) * result) { \ |
| 59 | + return result->inner.value; \ |
| 60 | + } \ |
| 61 | + typed(json_string) result_unwrap_err(name)(result(name) * result) { \ |
| 62 | + return result->inner.err; \ |
63 | 63 | } |
64 | 64 |
|
65 | 65 | #ifndef __cplusplus |
|
0 commit comments