From 53d3fd9b909427b0ab00f43e952fcfca26b685d2 Mon Sep 17 00:00:00 2001 From: Julian Stecklina Date: Fri, 25 Nov 2022 23:54:50 +0100 Subject: [PATCH 1/5] Implement Display trait for uefi::Status --- uefi/src/result/status.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/uefi/src/result/status.rs b/uefi/src/result/status.rs index acc12ab65..d4e1edeea 100644 --- a/uefi/src/result/status.rs +++ b/uefi/src/result/status.rs @@ -168,6 +168,12 @@ impl From for Result<(), ()> { } } +impl core::fmt::Display for Status { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + Debug::fmt(self, f) + } +} + #[cfg(test)] mod tests { use super::*; From e7d72a910888675b3175150166200da0ee9e77b9 Mon Sep 17 00:00:00 2001 From: Julian Stecklina Date: Fri, 25 Nov 2022 23:55:36 +0100 Subject: [PATCH 2/5] Implement Display for uefi::Error --- uefi/src/result/error.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/uefi/src/result/error.rs b/uefi/src/result/error.rs index 1d0a73685..32ceca05e 100644 --- a/uefi/src/result/error.rs +++ b/uefi/src/result/error.rs @@ -1,5 +1,5 @@ use super::Status; -use core::fmt::Debug; +use core::fmt::{Debug, Display}; /// Errors emitted from UEFI entry point must propagate erronerous UEFI statuses, /// and may optionally propagate additional entry point-specific data. @@ -39,3 +39,9 @@ impl From for Error<()> { Self { status, data: () } } } + +impl Display for Error { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "UEFI Error {}: {}", self.status(), self.data()) + } +} From 681c64d722248340709e0dfc0c94adbfce69f412 Mon Sep 17 00:00:00 2001 From: Julian Stecklina Date: Sat, 26 Nov 2022 00:15:26 +0100 Subject: [PATCH 3/5] Implement Error trait for uefi::Error This is useful to integrate with error handling libaries, such as anyhow. --- uefi/src/lib.rs | 1 + uefi/src/result/error.rs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/uefi/src/lib.rs b/uefi/src/lib.rs index ee6fa3d16..f30646fc7 100644 --- a/uefi/src/lib.rs +++ b/uefi/src/lib.rs @@ -41,6 +41,7 @@ #![feature(maybe_uninit_slice)] #![feature(negative_impls)] #![feature(ptr_metadata)] +#![feature(error_in_core)] #![cfg_attr(feature = "alloc", feature(vec_into_raw_parts))] #![cfg_attr(docsrs, feature(doc_auto_cfg))] #![no_std] diff --git a/uefi/src/result/error.rs b/uefi/src/result/error.rs index 32ceca05e..930e91a4b 100644 --- a/uefi/src/result/error.rs +++ b/uefi/src/result/error.rs @@ -45,3 +45,5 @@ impl Display for Error { write!(f, "UEFI Error {}: {}", self.status(), self.data()) } } + +impl core::error::Error for Error {} From 253a645ea4c3109bb9d7de55261db491e1437232 Mon Sep 17 00:00:00 2001 From: Julian Stecklina Date: Sat, 26 Nov 2022 00:22:54 +0100 Subject: [PATCH 4/5] Bump MSRV nightly to 2022-08-25 ... to enable error_in_core feature. --- .github/workflows/msrv_toolchain.toml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/msrv_toolchain.toml b/.github/workflows/msrv_toolchain.toml index e95bd0892..35936f6ea 100644 --- a/.github/workflows/msrv_toolchain.toml +++ b/.github/workflows/msrv_toolchain.toml @@ -1,4 +1,4 @@ [toolchain] # Oldest nightly that currently works with `cargo xtask build`. -channel = "nightly-2022-08-08" +channel = "nightly-2022-08-25" components = ["rust-src"] diff --git a/README.md b/README.md index 7d0b13bfb..9d8571bb4 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ prerequisites for running the tests. For instructions on how to create your own UEFI apps, see the [BUILDING.md](BUILDING.md) file. The uefi-rs crates currently require some [unstable features]. -The nightly MSRV is currently 2022-08-08. +The nightly MSRV is currently 2022-08-25. [unstable features]: https://github.com/rust-osdev/uefi-rs/issues/452 From 08b86e250a71b2438c4c46d45b510357be79269b Mon Sep 17 00:00:00 2001 From: Julian Stecklina Date: Sat, 26 Nov 2022 00:34:48 +0100 Subject: [PATCH 5/5] Update changelog for error handling trait implementation --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8e4c322f..882561632 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - Added `TryFrom` implementation for `CStr8`. - Added `Directory::read_entry_boxed` which works similar to `File::get_boxed_info`. This allows easier iteration over the entries in a directory. +- Added an `core::error::Error` implementation for `Error` to ease + integration with error-handling crates. ## uefi-macros - [Unreleased]