Skip to content

Commit 0ffc813

Browse files
Use StatusExt::to_result instead of Result::from/Status::into
1 parent fd54334 commit 0ffc813

File tree

23 files changed

+108
-103
lines changed

23 files changed

+108
-103
lines changed

uefi-services/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn init(st: &mut SystemTable<Boot>) -> Result {
8282
unsafe {
8383
// Avoid double initialization.
8484
if SYSTEM_TABLE.is_some() {
85-
return Status::SUCCESS.into();
85+
return Status::SUCCESS.to_result();
8686
}
8787

8888
// Setup the system table singleton

uefi/src/proto/console/gop.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl GraphicsOutput {
119119
///
120120
/// This function will invalidate the current framebuffer.
121121
pub fn set_mode(&mut self, mode: &Mode) -> Result {
122-
(self.set_mode)(self, mode.index).into()
122+
(self.set_mode)(self, mode.index).to_result()
123123
}
124124

125125
/// Performs a blt (block transfer) operation on the frame buffer.
@@ -147,7 +147,7 @@ impl GraphicsOutput {
147147
height,
148148
0,
149149
)
150-
.into()
150+
.to_result()
151151
}
152152
BltOp::VideoToBltBuffer {
153153
buffer,
@@ -170,7 +170,7 @@ impl GraphicsOutput {
170170
height,
171171
0,
172172
)
173-
.into(),
173+
.to_result(),
174174
BltRegion::SubRectangle {
175175
coords: (dest_x, dest_y),
176176
px_stride,
@@ -186,7 +186,7 @@ impl GraphicsOutput {
186186
height,
187187
px_stride * core::mem::size_of::<BltPixel>(),
188188
)
189-
.into(),
189+
.to_result(),
190190
}
191191
}
192192
BltOp::BufferToVideo {
@@ -210,7 +210,7 @@ impl GraphicsOutput {
210210
height,
211211
0,
212212
)
213-
.into(),
213+
.to_result(),
214214
BltRegion::SubRectangle {
215215
coords: (src_x, src_y),
216216
px_stride,
@@ -226,7 +226,7 @@ impl GraphicsOutput {
226226
height,
227227
px_stride * core::mem::size_of::<BltPixel>(),
228228
)
229-
.into(),
229+
.to_result(),
230230
}
231231
}
232232
BltOp::VideoToVideo {
@@ -248,7 +248,7 @@ impl GraphicsOutput {
248248
height,
249249
0,
250250
)
251-
.into()
251+
.to_result()
252252
}
253253
}
254254
}

uefi/src/proto/console/pointer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl Pointer {
2424
///
2525
/// - `DeviceError` if the device is malfunctioning and cannot be reset.
2626
pub fn reset(&mut self, extended_verification: bool) -> Result {
27-
(self.reset)(self, extended_verification).into()
27+
(self.reset)(self, extended_verification).to_result()
2828
}
2929

3030
/// Retrieves the pointer device's current state, if a state change occurred

uefi/src/proto/console/serial.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct Serial {
3939
impl Serial {
4040
/// Reset the device.
4141
pub fn reset(&mut self) -> Result {
42-
(self.reset)(self).into()
42+
(self.reset)(self).to_result()
4343
}
4444

4545
/// Returns the current I/O mode.
@@ -71,7 +71,7 @@ impl Serial {
7171
mode.data_bits as u8,
7272
mode.stop_bits,
7373
)
74-
.into()
74+
.to_result()
7575
}
7676

7777
/// Retrieve the device's current control bits.
@@ -85,7 +85,7 @@ impl Serial {
8585
/// Not all bits can be modified with this function. A mask of the allowed
8686
/// bits is stored in the [`ControlBits::SETTABLE`] constant.
8787
pub fn set_control_bits(&mut self, bits: ControlBits) -> Result {
88-
(self.set_control_bits)(self, bits).into()
88+
(self.set_control_bits)(self, bits).to_result()
8989
}
9090

9191
/// Reads data from this device.

uefi/src/proto/console/text/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Input {
2121
///
2222
/// - `DeviceError` if the device is malfunctioning and cannot be reset.
2323
pub fn reset(&mut self, extended_verification: bool) -> Result {
24-
(self.reset)(self, extended_verification).into()
24+
(self.reset)(self, extended_verification).to_result()
2525
}
2626

2727
/// Reads the next keystroke from the input device, if any.

uefi/src/proto/console/text/output.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ pub struct Output {
4343
impl Output {
4444
/// Resets and clears the text output device hardware.
4545
pub fn reset(&mut self, extended: bool) -> Result {
46-
(self.reset)(self, extended).into()
46+
(self.reset)(self, extended).to_result()
4747
}
4848

4949
/// Clears the output screen.
5050
///
5151
/// The background is set to the current background color.
5252
/// The cursor is moved to (0, 0).
5353
pub fn clear(&mut self) -> Result {
54-
(self.clear_screen)(self).into()
54+
(self.clear_screen)(self).to_result()
5555
}
5656

5757
/// Writes a string to the output device.
5858
pub fn output_string(&mut self, string: &CStr16) -> Result {
59-
unsafe { (self.output_string)(self, string.as_ptr()) }.into()
59+
unsafe { (self.output_string)(self, string.as_ptr()) }.to_result()
6060
}
6161

6262
/// Writes a string to the output device. If the string contains
@@ -125,7 +125,7 @@ impl Output {
125125

126126
/// Sets a mode as current.
127127
pub fn set_mode(&mut self, mode: OutputMode) -> Result {
128-
(self.set_mode)(self, mode.index).into()
128+
(self.set_mode)(self, mode.index).to_result()
129129
}
130130

131131
/// Returns whether the cursor is currently shown or not.
@@ -139,7 +139,7 @@ impl Output {
139139
/// The output device may not support this operation, in which case an
140140
/// `Unsupported` error will be returned.
141141
pub fn enable_cursor(&mut self, visible: bool) -> Result {
142-
(self.enable_cursor)(self, visible).into()
142+
(self.enable_cursor)(self, visible).to_result()
143143
}
144144

145145
/// Returns the column and row of the cursor.
@@ -154,7 +154,7 @@ impl Output {
154154
///
155155
/// This function will fail if the cursor's new position would exceed the screen's bounds.
156156
pub fn set_cursor_position(&mut self, column: usize, row: usize) -> Result {
157-
(self.set_cursor_position)(self, column, row).into()
157+
(self.set_cursor_position)(self, column, row).to_result()
158158
}
159159

160160
/// Sets the text and background colors for the console.
@@ -168,7 +168,7 @@ impl Output {
168168
assert!(bgc < 8, "An invalid background color was requested");
169169

170170
let attr = ((bgc & 0x7) << 4) | (fgc & 0xF);
171-
(self.set_attribute)(self, attr).into()
171+
(self.set_attribute)(self, attr).to_result()
172172
}
173173

174174
/// Get a reference to `OutputData`. The lifetime of the reference is tied

uefi/src/proto/debug/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl DebugSupport {
9595
}
9696

9797
// Safety: As we've validated the `processor_index`, this should always be safe
98-
(self.register_periodic_callback)(self, processor_index, callback).into()
98+
(self.register_periodic_callback)(self, processor_index, callback).to_result()
9999
}
100100

101101
/// Registers a function to be called when a given processor exception occurs.
@@ -119,7 +119,8 @@ impl DebugSupport {
119119
}
120120

121121
// Safety: As we've validated the `processor_index`, this should always be safe
122-
(self.register_exception_callback)(self, processor_index, callback, exception_type).into()
122+
(self.register_exception_callback)(self, processor_index, callback, exception_type)
123+
.to_result()
123124
}
124125

125126
/// Invalidates processor instruction cache for a memory range for a given `processor_index`.
@@ -140,7 +141,7 @@ impl DebugSupport {
140141

141142
// per the UEFI spec, this call should only return EFI_SUCCESS
142143
// Safety: As we've validated the `processor_index`, this should always be safe
143-
(self.invalidate_instruction_cache)(self, processor_index, start, length).into()
144+
(self.invalidate_instruction_cache)(self, processor_index, start, length).to_result()
144145
}
145146
}
146147

@@ -195,7 +196,7 @@ pub struct DebugPort {
195196
impl DebugPort {
196197
/// Resets the debugport device.
197198
pub fn reset(&self) -> Result {
198-
(self.reset)(self).into()
199+
(self.reset)(self).to_result()
199200
}
200201

201202
/// Write data to the debugport device.
@@ -236,6 +237,6 @@ impl DebugPort {
236237

237238
/// Check to see if any data is available to be read from the debugport device.
238239
pub fn poll(&self) -> Result {
239-
(self.poll)(self).into()
240+
(self.poll)(self).to_result()
240241
}
241242
}

uefi/src/proto/media/block.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Block I/O protocols.
22
33
use crate::proto::unsafe_protocol;
4-
use crate::{Result, Status};
4+
use crate::{Result, Status, StatusExt};
55

66
/// The Block I/O protocol.
77
#[repr(C)]
@@ -44,7 +44,7 @@ impl BlockIO {
4444
/// # Errors
4545
/// * `uefi::Status::DEVICE_ERROR` The block device is not functioning correctly and could not be reset.
4646
pub fn reset(&mut self, extended_verification: bool) -> Result {
47-
(self.reset)(self, extended_verification).into()
47+
(self.reset)(self, extended_verification).to_result()
4848
}
4949

5050
/// Read the requested number of blocks from the device.
@@ -65,7 +65,7 @@ impl BlockIO {
6565
/// proper alignment.
6666
pub fn read_blocks(&self, media_id: u32, lba: Lba, buffer: &mut [u8]) -> Result {
6767
let buffer_size = buffer.len();
68-
(self.read_blocks)(self, media_id, lba, buffer_size, buffer.as_mut_ptr()).into()
68+
(self.read_blocks)(self, media_id, lba, buffer_size, buffer.as_mut_ptr()).to_result()
6969
}
7070

7171
/// Writes the requested number of blocks to the device.
@@ -87,7 +87,7 @@ impl BlockIO {
8787
/// on proper alignment.
8888
pub fn write_blocks(&mut self, media_id: u32, lba: Lba, buffer: &[u8]) -> Result {
8989
let buffer_size = buffer.len();
90-
(self.write_blocks)(self, media_id, lba, buffer_size, buffer.as_ptr()).into()
90+
(self.write_blocks)(self, media_id, lba, buffer_size, buffer.as_ptr()).to_result()
9191
}
9292

9393
/// Flushes all modified data to a physical block device.
@@ -96,7 +96,7 @@ impl BlockIO {
9696
/// * `uefi::Status::DEVICE_ERROR` The device reported an error while attempting to write data.
9797
/// * `uefi::Status::NO_MEDIA` There is no media in the device.
9898
pub fn flush_blocks(&mut self) -> Result {
99-
(self.flush_blocks)(self).into()
99+
(self.flush_blocks)(self).to_result()
100100
}
101101
}
102102

uefi/src/proto/media/disk.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Disk I/O protocols.
22
33
use crate::proto::unsafe_protocol;
4-
use crate::{Event, Result, Status};
4+
use crate::{Event, Result, Status, StatusExt};
55
use core::ptr::NonNull;
66

77
/// The disk I/O protocol.
@@ -46,7 +46,7 @@ impl DiskIo {
4646
/// * `uefi::status::NO_MEDIA` There is no medium in the device.
4747
/// * `uefi::status::MEDIA_CHANGED` `media_id` is not for the current medium.
4848
pub fn read_disk(&self, media_id: u32, offset: u64, buffer: &mut [u8]) -> Result {
49-
(self.read_disk)(self, media_id, offset, buffer.len(), buffer.as_mut_ptr()).into()
49+
(self.read_disk)(self, media_id, offset, buffer.len(), buffer.as_mut_ptr()).to_result()
5050
}
5151

5252
/// Writes bytes to the disk device.
@@ -65,7 +65,7 @@ impl DiskIo {
6565
/// * `uefi::status::MEDIA_CHANGED` `media_id` is not for the current medium.
6666
/// * `uefi::status::WRITE_PROTECTED` The device cannot be written to.
6767
pub fn write_disk(&mut self, media_id: u32, offset: u64, buffer: &[u8]) -> Result {
68-
(self.write_disk)(self, media_id, offset, buffer.len(), buffer.as_ptr()).into()
68+
(self.write_disk)(self, media_id, offset, buffer.len(), buffer.as_ptr()).to_result()
6969
}
7070
}
7171

@@ -115,7 +115,7 @@ impl DiskIo2 {
115115
/// * `uefi::status::DEVICE_ERROR` The device reported an error while performing
116116
/// the cancel operation.
117117
pub fn cancel(&mut self) -> Result {
118-
(self.cancel)(self).into()
118+
(self.cancel)(self).to_result()
119119
}
120120

121121
/// Reads bytes from the disk device.
@@ -149,7 +149,7 @@ impl DiskIo2 {
149149
len: usize,
150150
buffer: *mut u8,
151151
) -> Result {
152-
(self.read_disk_ex)(self, media_id, offset, token, len, buffer).into()
152+
(self.read_disk_ex)(self, media_id, offset, token, len, buffer).to_result()
153153
}
154154

155155
/// Writes bytes to the disk device.
@@ -184,7 +184,7 @@ impl DiskIo2 {
184184
len: usize,
185185
buffer: *const u8,
186186
) -> Result {
187-
(self.write_disk_ex)(self, media_id, offset, token, len, buffer).into()
187+
(self.write_disk_ex)(self, media_id, offset, token, len, buffer).to_result()
188188
}
189189

190190
/// Flushes all modified data to the physical device.
@@ -202,6 +202,6 @@ impl DiskIo2 {
202202
/// the flush operation.
203203
/// * `uefi::status::WRITE_PROTECTED` The device cannot be written to.
204204
pub fn flush_disk(&mut self, token: Option<NonNull<DiskIo2Token>>) -> Result {
205-
(self.flush_disk_ex)(self, token).into()
205+
(self.flush_disk_ex)(self, token).to_result()
206206
}
207207
}

uefi/src/proto/media/file/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub trait File: Sized {
9090
///
9191
/// * [`uefi::Status::WARN_DELETE_FAILURE`]
9292
fn delete(mut self) -> Result {
93-
let result = (self.imp().delete)(self.imp()).into();
93+
let result = (self.imp().delete)(self.imp()).to_result();
9494
mem::forget(self);
9595
result
9696
}
@@ -165,7 +165,7 @@ pub trait File: Sized {
165165
fn set_info<Info: FileProtocolInfo + ?Sized>(&mut self, info: &Info) -> Result {
166166
let info_ptr = (info as *const Info).cast::<c_void>();
167167
let info_size = mem::size_of_val(info);
168-
unsafe { (self.imp().set_info)(self.imp(), &Info::GUID, info_size, info_ptr).into() }
168+
unsafe { (self.imp().set_info)(self.imp(), &Info::GUID, info_size, info_ptr).to_result() }
169169
}
170170

171171
/// Flushes all modified data associated with the file handle to the device
@@ -181,7 +181,7 @@ pub trait File: Sized {
181181
/// * [`uefi::Status::ACCESS_DENIED`]
182182
/// * [`uefi::Status::VOLUME_FULL`]
183183
fn flush(&mut self) -> Result {
184-
(self.imp().flush)(self.imp()).into()
184+
(self.imp().flush)(self.imp()).to_result()
185185
}
186186

187187
/// Read the dynamically allocated info for a file.
@@ -307,7 +307,7 @@ impl File for FileHandle {
307307

308308
impl Drop for FileHandle {
309309
fn drop(&mut self) {
310-
let result: Result = (self.imp().close)(self.imp()).into();
310+
let result: Result = (self.imp().close)(self.imp()).to_result();
311311
// The spec says this always succeeds.
312312
result.expect("Failed to close file");
313313
}

uefi/src/proto/media/file/regular.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl RegularFile {
112112
///
113113
/// * [`uefi::Status::DEVICE_ERROR`]
114114
pub fn set_position(&mut self, position: u64) -> Result {
115-
(self.imp().set_position)(self.imp(), position).into()
115+
(self.imp().set_position)(self.imp(), position).to_result()
116116
}
117117
}
118118

0 commit comments

Comments
 (0)