From 51602d12357b6394c05e0e6d22cad2f6cf4887f2 Mon Sep 17 00:00:00 2001 From: Ryan Cohen Date: Sun, 18 Dec 2022 15:58:34 -0500 Subject: [PATCH] Implement `Error` and `Display` traits for `FromStrError` For issue #594. --- uefi/src/data_types/owned_strs.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/uefi/src/data_types/owned_strs.rs b/uefi/src/data_types/owned_strs.rs index eebae6b11..8c681da98 100644 --- a/uefi/src/data_types/owned_strs.rs +++ b/uefi/src/data_types/owned_strs.rs @@ -15,6 +15,22 @@ pub enum FromStrError { InteriorNul, } +impl fmt::Display for FromStrError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "UCS-2 Conversion Error: {}", + match self { + Self::InvalidChar => "Invalid character", + Self::InteriorNul => "Interior null terminator", + } + ) + } +} + +#[cfg(feature = "unstable")] +impl core::error::Error for FromStrError {} + /// An owned UCS-2 null-terminated string. /// /// For convenience, a [CString16] is comparable with `&str` and `String` from the standard library