Skip to content

Commit 17b40b1

Browse files
dotcarmenlinusg
authored andcommitted
lib/std/os/uefi/status.zig: add error to enum conversion fn
1 parent 0f60569 commit 17b40b1

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

lib/std/os/uefi/status.zig

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,57 @@ pub const Status = enum(usize) {
231231
else => {},
232232
}
233233
}
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+
}
234279
};
235280

236281
test "status" {
237282
var st: Status = .device_error;
238283
try testing.expectError(error.DeviceError, st.err());
284+
try testing.expectEqual(st, Status.fromError(st.err()));
239285

240286
st = .success;
241287
try st.err();

0 commit comments

Comments
 (0)