@@ -231,11 +231,57 @@ pub const Status = enum(usize) {
231
231
else = > {},
232
232
}
233
233
}
234
+
235
+ pub fn fromError (e : Error ) Status {
236
+ return switch (e ) {
237
+ Error .Aborted = > .aborted ,
238
+ Error .AccessDenied = > .access_denied ,
239
+ Error .AlreadyStarted = > .already_started ,
240
+ Error .BadBufferSize = > .bad_buffer_size ,
241
+ Error .BufferTooSmall = > .buffer_too_small ,
242
+ Error .CompromisedData = > .compromised_data ,
243
+ Error .ConnectionFin = > .connection_fin ,
244
+ Error .ConnectionRefused = > .connection_refused ,
245
+ Error .ConnectionReset = > .connection_reset ,
246
+ Error .CrcError = > .crc_error ,
247
+ Error .DeviceError = > .device_error ,
248
+ Error .EndOfFile = > .end_of_file ,
249
+ Error .EndOfMedia = > .end_of_media ,
250
+ Error .HostUnreachable = > .host_unreachable ,
251
+ Error .HttpError = > .http_error ,
252
+ Error .IcmpError = > .icmp_error ,
253
+ Error .IncompatibleVersion = > .incompatible_version ,
254
+ Error .InvalidLanguage = > .invalid_language ,
255
+ Error .InvalidParameter = > .invalid_parameter ,
256
+ Error .IpAddressConflict = > .ip_address_conflict ,
257
+ Error .LoadError = > .load_error ,
258
+ Error .MediaChanged = > .media_changed ,
259
+ Error .NetworkUnreachable = > .network_unreachable ,
260
+ Error .NoMapping = > .no_mapping ,
261
+ Error .NoMedia = > .no_media ,
262
+ Error .NoResponse = > .no_response ,
263
+ Error .NotFound = > .not_found ,
264
+ Error .NotReady = > .not_ready ,
265
+ Error .NotStarted = > .not_started ,
266
+ Error .OutOfResources = > .out_of_resources ,
267
+ Error .PortUnreachable = > .port_unreachable ,
268
+ Error .ProtocolError = > .protocol_error ,
269
+ Error .ProtocolUnreachable = > .protocol_unreachable ,
270
+ Error .SecurityViolation = > .security_violation ,
271
+ Error .TftpError = > .tftp_error ,
272
+ Error .Timeout = > .timeout ,
273
+ Error .Unsupported = > .unsupported ,
274
+ Error .VolumeCorrupted = > .volume_corrupted ,
275
+ Error .VolumeFull = > .volume_full ,
276
+ Error .WriteProtected = > .write_protected ,
277
+ };
278
+ }
234
279
};
235
280
236
281
test "status" {
237
282
var st : Status = .device_error ;
238
283
try testing .expectError (error .DeviceError , st .err ());
284
+ try testing .expectEqual (st , Status .fromError (st .err ()));
239
285
240
286
st = .success ;
241
287
try st .err ();
0 commit comments