Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 123979e

Browse files
HadrienG2GabrielMajeri
authored andcommitted
Fix Completion documentation and add assertion that status isn't an error
1 parent 12cc5c9 commit 123979e

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

‎src/result/completion.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::Status;
22
use log::warn;
33

44
/// This type is used when an UEFI operation has completed, but some non-fatal
5-
/// problems may have been encountered along the way
5+
/// problems (UEFI warnings) may have been encountered along the way
66
#[must_use]
77
#[derive(Clone, Copy, Debug, PartialEq)]
88
pub struct Completion<T> {
@@ -11,8 +11,11 @@ pub struct Completion<T> {
1111
}
1212

1313
impl<T> Completion<T> {
14-
/// Build a completion from a non-warning status and a function result
14+
/// Build a completion from a non-error status and a function result
1515
pub fn new(status: Status, result: T) -> Self {
16+
if status.is_error() {
17+
built_with_error(status);
18+
}
1619
Self { status, result }
1720
}
1821

@@ -38,7 +41,7 @@ impl<T> Completion<T> {
3841
pub fn unwrap(self) -> T {
3942
if self.status != Status::SUCCESS {
4043
unwrap_failed(
41-
"Called `Completion::unwrap()` on a `Warning` value",
44+
"Called `Completion::unwrap()` with a warning status",
4245
self.status,
4346
);
4447
}
@@ -69,10 +72,7 @@ impl<T> Completion<T> {
6972
if extra_status.is_success() {
7073
self
7174
} else {
72-
Completion {
73-
status: extra_status,
74-
result: self.log(),
75-
}
75+
Completion::new(extra_status, self.log())
7676
}
7777
}
7878
}
@@ -81,21 +81,24 @@ impl<T> Completion<T> {
8181

8282
impl From<Status> for Completion<()> {
8383
fn from(status: Status) -> Self {
84-
Completion{status, result:()}
84+
Completion::new(status, ())
8585
}
8686
}
8787

8888
impl<T> From<T> for Completion<T> {
8989
fn from(result: T) -> Self {
90-
Completion {
91-
status: Status::SUCCESS,
92-
result,
93-
}
90+
Completion::new(Status::SUCCESS, result)
9491
}
9592
}
9693

9794
// These are separate functions to reduce the code size of the methods
9895

96+
#[inline(never)]
97+
#[cold]
98+
fn built_with_error(error: Status) -> ! {
99+
panic!("Completion was incorrectly built with error status: {:?}", error)
100+
}
101+
99102
#[inline(never)]
100103
#[cold]
101104
fn unwrap_failed(msg: &str, warning: Status) -> ! {

‎src/result/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub use self::error::Error;
2525
mod status;
2626
pub use self::status::Status;
2727

28-
/// Return type of most UEFI functions. Both success and error payloads are optional
28+
/// Return type of most UEFI functions. Both success and error payloads are optional.
2929
pub type Result<Output = (), ErrData = ()> =
3030
core::result::Result<Completion<Output>, Error<ErrData>>;
3131

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /