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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#[macro_export]
macro_rules! cjid {
    [$n:expr] => {
        maelstrom_base::ClientJobId::from($n)
    };
}

#[macro_export]
macro_rules! cid {
    [$n:expr] => { maelstrom_base::ClientId::from($n) };
}

#[macro_export]
macro_rules! wid {
    [$n:expr] => { maelstrom_base::WorkerId::from($n) };
}

#[macro_export]
macro_rules! jid {
    [$n:expr] => {
        jid!($n, $n)
    };
    [$cid:expr, $cjid:expr] => {
        maelstrom_base::JobId{cid: cid![$cid], cjid: cjid![$cjid]}
    };
}

#[macro_export]
macro_rules! spec {
    [1] => {
        maelstrom_base::JobSpec::new("test_1", maelstrom_base::nonempty![digest!(1)])
    };
    [2] => {
        maelstrom_base::JobSpec::new("test_2", maelstrom_base::nonempty![digest!(2)])
            .arguments(["arg_1"])
    };
    [3] => {
        maelstrom_base::JobSpec::new("test_3", maelstrom_base::nonempty![digest!(3)])
            .arguments(["arg_1", "arg_2"])
    };
    [4] => {
        maelstrom_base::JobSpec::new("test_4", maelstrom_base::nonempty![digest!(4)])
            .arguments(["arg_1", "arg_2", "arg_3"])
    };
    [$n:literal] => {
        maelstrom_base::JobSpec::new(concat!("test_", stringify!($n)), maelstrom_base::nonempty![digest!($n)])
            .arguments(["arg_1"])
    };
    [$n:literal, [$($digest:expr),*]] => {
        {
            let mut spec = spec![$n];
            spec.layers = maelstrom_base::nonempty![$(digest!($digest)),*];
            spec
        }
    }
}

#[macro_export]
macro_rules! result {
    [1] => {
        Ok(maelstrom_base::JobSuccess {
            status: maelstrom_base::JobStatus::Exited(0),
            stdout: maelstrom_base::JobOutputResult::None,
            stderr: maelstrom_base::JobOutputResult::None,
        })
    };
    [2] => {
        Ok(maelstrom_base::JobSuccess {
            status: maelstrom_base::JobStatus::Exited(1),
            stdout: maelstrom_base::JobOutputResult::None,
            stderr: maelstrom_base::JobOutputResult::None,
        })
    };
    [3] => {
        Ok(maelstrom_base::JobSuccess {
            status: maelstrom_base::JobStatus::Signaled(15),
            stdout: maelstrom_base::JobOutputResult::None,
            stderr: maelstrom_base::JobOutputResult::None,
        })
    };
    [$n:expr] => {
        Ok(maelstrom_base::JobSuccess {
            status: maelstrom_base::JobStatus::Exited($n),
            stdout: maelstrom_base::JobOutputResult::None,
            stderr: maelstrom_base::JobOutputResult::None,
        })
    };
}

#[macro_export]
macro_rules! digest {
    [$n:expr] => {
        maelstrom_base::Sha256Digest::from($n as u64)
    }
}

#[macro_export]
macro_rules! path_buf {
    ($e:expr) => {
        std::path::Path::new($e).to_path_buf()
    };
}

#[macro_export]
macro_rules! path_buf_vec {
    [$($e:expr),*] => {
        vec![$($crate::path_buf!($e)),*]
    };
}

#[macro_export]
macro_rules! utf8_path_buf {
    ($e:expr) => {
        maelstrom_base::Utf8PathBuf::from($e)
    };
}

#[macro_export]
macro_rules! utf8_path_buf_vec {
    [$($e:expr),*] => {
        vec![$($crate::utf8_path_buf!($e)),*]
    };
}

#[macro_export]
macro_rules! long_path {
    ($prefix:expr, $n:expr) => {
        format!("{}/{:0>64x}", $prefix, $n).into()
    };
    ($prefix:expr, $n:expr, $s:expr) => {
        format!("{}/{:0>64x}.{}", $prefix, $n, $s).into()
    };
}

#[macro_export]
macro_rules! short_path {
    ($prefix:expr, $n:expr) => {
        format!("{}/{:0>16x}", $prefix, $n).into()
    };
    ($prefix:expr, $n:expr, $s:expr) => {
        format!("{}/{:0>16x}.{}", $prefix, $n, $s).into()
    };
}

#[macro_export]
macro_rules! boxed_u8 {
    ($n:literal) => {
        $n.to_vec().into_boxed_slice()
    };
}

#[macro_export]
macro_rules! string {
    ($e:expr) => {
        $e.to_string()
    };
}

#[macro_export]
macro_rules! string_vec {
    [$($e:expr),*] => {
        vec![$($e.to_string()),*]
    };
    [$($e:expr),*,] => {
        vec![$($e.to_string()),*]
    };
}

#[macro_export]
macro_rules! string_nonempty {
    [$($e:expr),*] => {
        nonempty![$($e.to_string()),*]
    };
    [$($e:expr),*,] => {
        nonempty![$($e.to_string()),*]
    };
}