aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/result.c
blob: 8fd2ca1e9c44f57b137c556df14ae7d8c7a50915 (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
58
59
60
61
62
63
64
65
// Result (Success/Failure) type info
#include <err.h>
#include <gc.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/param.h>

#include "enums.h"
#include "structs.h"
#include "text.h"
#include "util.h"

public
const TypeInfo_t Result$Success$$info = {
    .size = sizeof(Result$Success$$type),
    .align = __alignof__(Result$Success$$type),
    .tag = StructInfo,
    .StructInfo =
        {
            .name = "Success",
            .num_fields = 0,
        },
    .metamethods = Struct$metamethods,
};

public
const TypeInfo_t Result$Failure$$info = {
    .size = sizeof(Result$Failure$$type),
    .align = __alignof__(Result$Failure$$type),
    .tag = StructInfo,
    .StructInfo =
        {
            .name = "Failure",
            .num_fields = 1,
            .fields =
                (NamedType_t[1]){
                    {.name = "reason", .type = &Text$info},
                },
        },
    .metamethods = Struct$metamethods,
};

public
const TypeInfo_t Result$$info = {
    .size = sizeof(Result_t),
    .align = __alignof__(Result_t),
    .tag = EnumInfo,
    .EnumInfo =
        {
            .name = "Result",
            .num_tags = 2,
            .tags =
                (NamedType_t[2]){
                    {
                        .name = "Success",
                        .type = &Result$Success$$info,
                    },
                    {
                        .name = "Failure",
                        .type = &Result$Failure$$info,
                    },
                },
        },
    .metamethods = Enum$metamethods,
};