@@ -2,7 +2,7 @@ use super::Status;
2
2
use log:: warn;
3
3
4
4
/// 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
6
6
#[ must_use]
7
7
#[ derive( Clone , Copy , Debug , PartialEq ) ]
8
8
pub struct Completion < T > {
@@ -11,8 +11,11 @@ pub struct Completion<T> {
11
11
}
12
12
13
13
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
15
15
pub fn new ( status : Status , result : T ) -> Self {
16
+ if status. is_error ( ) {
17
+ built_with_error ( status) ;
18
+ }
16
19
Self { status, result }
17
20
}
18
21
@@ -38,7 +41,7 @@ impl<T> Completion<T> {
38
41
pub fn unwrap ( self ) -> T {
39
42
if self . status != Status :: SUCCESS {
40
43
unwrap_failed (
41
- "Called `Completion::unwrap()` on a `Warning` value " ,
44
+ "Called `Completion::unwrap()` with a warning status " ,
42
45
self . status ,
43
46
) ;
44
47
}
@@ -69,10 +72,7 @@ impl<T> Completion<T> {
69
72
if extra_status. is_success ( ) {
70
73
self
71
74
} else {
72
- Completion {
73
- status : extra_status,
74
- result : self . log ( ) ,
75
- }
75
+ Completion :: new ( extra_status, self . log ( ) )
76
76
}
77
77
}
78
78
}
@@ -81,21 +81,24 @@ impl<T> Completion<T> {
81
81
82
82
impl From < Status > for Completion < ( ) > {
83
83
fn from ( status : Status ) -> Self {
84
- Completion { status, result : ( ) }
84
+ Completion :: new ( status, ( ) )
85
85
}
86
86
}
87
87
88
88
impl < T > From < T > for Completion < T > {
89
89
fn from ( result : T ) -> Self {
90
- Completion {
91
- status : Status :: SUCCESS ,
92
- result,
93
- }
90
+ Completion :: new ( Status :: SUCCESS , result)
94
91
}
95
92
}
96
93
97
94
// These are separate functions to reduce the code size of the methods
98
95
96
+ #[ inline( never) ]
97
+ #[ cold]
98
+ fn built_with_error ( error : Status ) -> ! {
99
+ panic ! ( "Completion was incorrectly built with error status: {:?}" , error)
100
+ }
101
+
99
102
#[ inline( never) ]
100
103
#[ cold]
101
104
fn unwrap_failed ( msg : & str , warning : Status ) -> ! {
0 commit comments