Skip to content

Commit fd54334

Browse files
uefi: Add StatusExt::to_result
This will take the place of into/from for converting from Status to Result. Again, this is needed in preparation for moving `Status` to uefi-raw.
1 parent 7fa8e90 commit fd54334

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

uefi/src/result/status.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ impl Status {
131131

132132
/// Extension trait which provides some convenience methods for [`Status`].
133133
pub trait StatusExt {
134+
/// Converts this status code into a [`uefi::Result`].
135+
///
136+
/// If the status does not indicate success, the status representing the specific error
137+
/// code is embedded into the `Err` variant of type [`uefi::Error`].
138+
fn to_result(self) -> Result;
139+
134140
/// Converts this status code into a [`uefi::Result`] with a given `Ok` value.
135141
///
136142
/// If the status does not indicate success, the status representing the specific error
@@ -158,6 +164,15 @@ pub trait StatusExt {
158164
}
159165

160166
impl StatusExt for Status {
167+
#[inline]
168+
fn to_result(self) -> Result {
169+
if self.is_success() {
170+
Ok(())
171+
} else {
172+
Err(self.into())
173+
}
174+
}
175+
161176
#[inline]
162177
fn to_result_with_val<T>(self, val: impl FnOnce() -> T) -> Result<T, ()> {
163178
if self.is_success() {

0 commit comments

Comments
 (0)