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/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] 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 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 1d0a73685..930e91a4b 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,11 @@ 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()) + } +} + +impl core::error::Error for Error {} 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::*;