1//! Module for UEFI-specific error encodings. See [`Error`].
2
3use super::Status;
4use core::fmt::{Debug, Display};
5
6/// An UEFI-related error with optionally additional payload data. The error
7/// kind is encoded in the `status` field (see [`Status`]). Additional payload
8/// may be inside the `data` field.
9#[derive(Debug, PartialEq, Eq)]
10pub struct Error<Data: Debug = ()> {
11 status: Status,
12 data: Data,
13}
14
15impl<Data: Debug> Error<Data> {
16 /// Create an `Error`.
17 pub const fn new(status: Status, data: Data) -> Self {
18 Self { status, data }
19 }
20
21 /// Get error `Status`.
22 pub const fn status(&self) -> Status {
23 self.status
24 }
25
26 /// Get error data.
27 pub const fn data(&self) -> &Data {
28 &self.data
29 }
30
31 /// Split this error into its inner status and error data
32 #[allow(clippy::missing_const_for_fn)]
33 pub fn split(self) -> (Status, Data) {
34 (self.status, self.data)
35 }
36}
37
38// Errors without error data can be autogenerated from statuses
39
40impl From<Status> for Error<()> {
41 fn from(status: Status) -> Self {
42 Self { status, data: () }
43 }
44}
45
46impl<Data: Debug> Display for Error<Data> {
47 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
48 write!(f, "UEFI Error {}: {:?}", self.status(), self.data())
49 }
50}
51
52#[cfg(feature = "unstable")]
53impl<Data: Debug> core::error::Error for Error<Data> {}
54