Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/uefi/src/result/error.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / uefi / src / result / error.rs` 73 lines ยท 1977 bytes Raw Blame History 1 // SPDX-License-Identifier: MIT OR Apache-2.0 2 3 //! Module for UEFI-specific error encodings. See [`Error`]. 4 5 use super::Status; 6 use core::error; 7 use core::fmt::{self, Debug, Display, Formatter}; 8 9 /// An UEFI-related error with optionally additional payload data. The error 10 /// kind is encoded in the `status` field (see [`Status`]). Additional payload 11 /// may be inside the `data` field. 12 #[derive(Clone, Debug, PartialEq, Eq)] 13 pub struct Error { 14 status: Status, 15 data: Data, 16 } 17 18 impl Error { 19 /// Create an `Error`. 20 /// 21 /// # Panics 22 /// 23 /// Panics if `status` is [`Status::SUCCESS`]. 24 pub const fn new(status: Status, data: Data) -> Self { 25 assert!(!matches!(status, Status::SUCCESS)); 26 Self { status, data } 27 } 28 29 /// Get error `Status`. 30 pub const fn status(&self) -> Status { 31 self.status 32 } 33 34 /// Get error data. 35 pub const fn data(&self) -> &Data { 36 &self.data 37 } 38 39 /// Split this error into its inner status and error data 40 pub fn split(self) -> (Status, Data) { 41 (self.status, self.data) 42 } 43 } 44 45 // Errors without error data can be autogenerated from statuses 46 47 impl From for Error<()> { 48 fn from(status: Status) -> Self { 49 Self::new(status, ()) 50 } 51 } 52 53 impl Display for Error { 54 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { 55 write!(f, "UEFI Error {}: {:?}", self.status(), self.data()) 56 } 57 } 58 59 impl Error { 60 /// Transforms the generic payload of an error to `()`. This is useful if 61 /// you want 62 /// - to retain the erroneous status code, 63 /// - do not care about the payload, and 64 /// - refrain from generic type complexity in a higher API level. 65 pub const fn to_err_without_payload(&self) -> Error<()> { 66 Error { 67 status: self.status, 68 data: (), 69 } 70 } 71 } 72 73 impl error::Error for Error {}