Skip to content

Commit 7fa8e90

Browse files
uefi: Rename into_with* to to_result_with*
Slightly more verbose, but easier to read. Also fits better with a `to_result` function (in the next commit).
1 parent ffac3af commit 7fa8e90

File tree

21 files changed

+113
-106
lines changed

21 files changed

+113
-106
lines changed

uefi/src/mem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ mod tests {
146146

147147
if buf.len() < required_size {
148148
// We can use an zero-length buffer to find the required size.
149-
return Status::BUFFER_TOO_SMALL.into_with(|| panic!(), |_| Some(required_size));
149+
return Status::BUFFER_TOO_SMALL.to_result_with(|| panic!(), |_| Some(required_size));
150150
};
151151

152152
// assert alignment

uefi/src/proto/console/gop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl GraphicsOutput {
9494
let mut info_sz = 0;
9595
let mut info = ptr::null();
9696

97-
(self.query_mode)(self, index, &mut info_sz, &mut info).into_with_val(|| {
97+
(self.query_mode)(self, index, &mut info_sz, &mut info).to_result_with_val(|| {
9898
let info = unsafe { *info };
9999
Mode {
100100
index,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Pointer {
4040

4141
match (self.get_state)(self, pointer_state.as_mut_ptr()) {
4242
Status::NOT_READY => Ok(None),
43-
other => other.into_with_val(|| unsafe { Some(pointer_state.assume_init()) }),
43+
other => other.to_result_with_val(|| unsafe { Some(pointer_state.assume_init()) }),
4444
}
4545
}
4646

uefi/src/proto/console/serial.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Serial {
7777
/// Retrieve the device's current control bits.
7878
pub fn get_control_bits(&self) -> Result<ControlBits> {
7979
let mut bits = ControlBits::empty();
80-
(self.get_control_bits)(self, &mut bits).into_with_val(|| bits)
80+
(self.get_control_bits)(self, &mut bits).to_result_with_val(|| bits)
8181
}
8282

8383
/// Sets the device's new control bits.
@@ -95,7 +95,7 @@ impl Serial {
9595
/// bytes were actually read from the device.
9696
pub fn read(&mut self, data: &mut [u8]) -> Result<(), usize> {
9797
let mut buffer_size = data.len();
98-
unsafe { (self.read)(self, &mut buffer_size, data.as_mut_ptr()) }.into_with(
98+
unsafe { (self.read)(self, &mut buffer_size, data.as_mut_ptr()) }.to_result_with(
9999
|| debug_assert_eq!(buffer_size, data.len()),
100100
|_| buffer_size,
101101
)
@@ -108,7 +108,7 @@ impl Serial {
108108
/// were actually written to the device.
109109
pub fn write(&mut self, data: &[u8]) -> Result<(), usize> {
110110
let mut buffer_size = data.len();
111-
unsafe { (self.write)(self, &mut buffer_size, data.as_ptr()) }.into_with(
111+
unsafe { (self.write)(self, &mut buffer_size, data.as_ptr()) }.to_result_with(
112112
|| debug_assert_eq!(buffer_size, data.len()),
113113
|_| buffer_size,
114114
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Input {
7777

7878
match (self.read_key_stroke)(self, key.as_mut_ptr()) {
7979
Status::NOT_READY => Ok(None),
80-
other => other.into_with_val(|| Some(unsafe { key.assume_init() }.into())),
80+
other => other.to_result_with_val(|| Some(unsafe { key.assume_init() }.into())),
8181
}
8282
}
8383

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl Output {
7979
pub fn test_string(&mut self, string: &CStr16) -> Result<bool> {
8080
match unsafe { (self.test_string)(self, string.as_ptr()) } {
8181
Status::UNSUPPORTED => Ok(false),
82-
other => other.into_with_val(|| true),
82+
other => other.to_result_with_val(|| true),
8383
}
8484
}
8585

@@ -106,7 +106,8 @@ impl Output {
106106
/// alternative to this method.
107107
fn query_mode(&self, index: usize) -> Result<(usize, usize)> {
108108
let (mut columns, mut rows) = (0, 0);
109-
(self.query_mode)(self, index, &mut columns, &mut rows).into_with_val(|| (columns, rows))
109+
(self.query_mode)(self, index, &mut columns, &mut rows)
110+
.to_result_with_val(|| (columns, rows))
110111
}
111112

112113
/// Returns the current text mode.

uefi/src/proto/debug/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl DebugPort {
210210
&mut buffer_size,
211211
data.as_ptr().cast::<c_void>(),
212212
)
213-
.into_with(
213+
.to_result_with(
214214
|| debug_assert_eq!(buffer_size, data.len()),
215215
|_| buffer_size,
216216
)
@@ -228,7 +228,7 @@ impl DebugPort {
228228
&mut buffer_size,
229229
data.as_mut_ptr().cast::<c_void>(),
230230
)
231-
.into_with(
231+
.to_result_with(
232232
|| debug_assert_eq!(buffer_size, data.len()),
233233
|_| buffer_size,
234234
)

uefi/src/proto/driver/component_name.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl ComponentName1 {
6262
let language = language_to_cstr(language)?;
6363
let mut driver_name = ptr::null();
6464
unsafe { (self.get_driver_name)(self, language.as_ptr(), &mut driver_name) }
65-
.into_with_val(|| unsafe { CStr16::from_ptr(driver_name.cast()) })
65+
.to_result_with_val(|| unsafe { CStr16::from_ptr(driver_name.cast()) })
6666
}
6767

6868
/// Get the human-readable name of a controller in the given language.
@@ -87,7 +87,7 @@ impl ComponentName1 {
8787
&mut driver_name,
8888
)
8989
}
90-
.into_with_val(|| unsafe { CStr16::from_ptr(driver_name.cast()) })
90+
.to_result_with_val(|| unsafe { CStr16::from_ptr(driver_name.cast()) })
9191
}
9292
}
9393

@@ -142,7 +142,7 @@ impl ComponentName2 {
142142
let language = language_to_cstr(language)?;
143143
let mut driver_name = ptr::null();
144144
unsafe { (self.get_driver_name)(self, language.as_ptr(), &mut driver_name) }
145-
.into_with_val(|| unsafe { CStr16::from_ptr(driver_name.cast()) })
145+
.to_result_with_val(|| unsafe { CStr16::from_ptr(driver_name.cast()) })
146146
}
147147

148148
/// Get the human-readable name of a controller in the given language.
@@ -167,7 +167,7 @@ impl ComponentName2 {
167167
&mut driver_name,
168168
)
169169
}
170-
.into_with_val(|| unsafe { CStr16::from_ptr(driver_name.cast()) })
170+
.to_result_with_val(|| unsafe { CStr16::from_ptr(driver_name.cast()) })
171171
}
172172
}
173173

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub trait File: Sized {
7676
attributes,
7777
)
7878
}
79-
.into_with_val(|| unsafe { FileHandle::new(ptr) })
79+
.to_result_with_val(|| unsafe { FileHandle::new(ptr) })
8080
}
8181

8282
/// Close this file handle. Same as dropping this structure.
@@ -128,7 +128,7 @@ pub trait File: Sized {
128128
buffer.as_mut_ptr(),
129129
)
130130
}
131-
.into_with(
131+
.to_result_with(
132132
|| unsafe { Info::from_uefi(buffer.as_mut_ptr().cast::<c_void>()) },
133133
|s| {
134134
if s == Status::BUFFER_TOO_SMALL {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl RegularFile {
4444
let status =
4545
unsafe { (self.imp().read)(self.imp(), &mut buffer_size, buffer.as_mut_ptr()) };
4646

47-
status.into_with(
47+
status.to_result_with(
4848
|| buffer_size,
4949
|s| {
5050
if s == Status::BUFFER_TOO_SMALL {
@@ -81,7 +81,7 @@ impl RegularFile {
8181
pub fn write(&mut self, buffer: &[u8]) -> Result<(), usize> {
8282
let mut buffer_size = buffer.len();
8383
unsafe { (self.imp().write)(self.imp(), &mut buffer_size, buffer.as_ptr()) }
84-
.into_with_err(|_| buffer_size)
84+
.to_result_with_err(|_| buffer_size)
8585
}
8686

8787
/// Get the file's current position
@@ -93,7 +93,7 @@ impl RegularFile {
9393
/// * [`uefi::Status::DEVICE_ERROR`]
9494
pub fn get_position(&mut self) -> Result<u64> {
9595
let mut pos = 0u64;
96-
(self.imp().get_position)(self.imp(), &mut pos).into_with_val(|| pos)
96+
(self.imp().get_position)(self.imp(), &mut pos).to_result_with_val(|| pos)
9797
}
9898

9999
/// Sets the file's current position

uefi/src/proto/media/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ impl SimpleFileSystem {
4949
pub fn open_volume(&mut self) -> Result<Directory> {
5050
let mut ptr = ptr::null_mut();
5151
(self.open_volume)(self, &mut ptr)
52-
.into_with_val(|| unsafe { Directory::new(FileHandle::new(ptr)) })
52+
.to_result_with_val(|| unsafe { Directory::new(FileHandle::new(ptr)) })
5353
}
5454
}

uefi/src/proto/network/pxe.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl BaseCode {
160160
false,
161161
)
162162
};
163-
status.into_with_val(|| buffer_size)
163+
status.to_result_with_val(|| buffer_size)
164164
}
165165

166166
/// Reads a file located on a TFTP server.
@@ -191,7 +191,7 @@ impl BaseCode {
191191
dont_use_buffer,
192192
)
193193
};
194-
status.into_with_val(|| buffer_size)
194+
status.to_result_with_val(|| buffer_size)
195195
}
196196

197197
/// Writes to a file located on a TFTP server.
@@ -320,7 +320,7 @@ impl BaseCode {
320320
false,
321321
)
322322
};
323-
status.into_with_val(|| buffer_size)
323+
status.to_result_with_val(|| buffer_size)
324324
}
325325

326326
/// Reads a file located on a MTFTP server.
@@ -352,7 +352,7 @@ impl BaseCode {
352352
dont_use_buffer,
353353
)
354354
};
355-
status.into_with_val(|| buffer_size)
355+
status.to_result_with_val(|| buffer_size)
356356
}
357357

358358
/// Reads a directory listing of a directory on a MTFTP server.
@@ -522,7 +522,7 @@ impl BaseCode {
522522
(&mut buffer[0] as *mut u8).cast(),
523523
)
524524
};
525-
status.into_with_val(|| buffer_size)
525+
status.to_result_with_val(|| buffer_size)
526526
}
527527

528528
/// Updates the IP receive filters of a network device and enables software

uefi/src/proto/network/snp.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ impl SimpleNetwork {
152152
let mut stats_table: NetworkStats = Default::default();
153153
let mut stats_size = core::mem::size_of::<NetworkStats>();
154154
let status = (self.statistics)(self, false, Some(&mut stats_size), Some(&mut stats_table));
155-
status.into_with_val(|| stats_table)
155+
status.to_result_with_val(|| stats_table)
156156
}
157157

158158
/// Convert a multicast IP address to a multicast HW MAC Address.
159159
pub fn mcast_ip_to_mac(&self, ipv6: bool, ip: IpAddress) -> Result<MacAddress> {
160160
let mut mac_address = MacAddress([0; 32]);
161161
let status = (self.mcast_ip_to_mac)(self, ipv6, &ip, &mut mac_address);
162-
status.into_with_val(|| mac_address)
162+
status.to_result_with_val(|| mac_address)
163163
}
164164

165165
/// Perform read operations on the NVRAM device attached to
@@ -192,15 +192,15 @@ impl SimpleNetwork {
192192
pub fn get_interrupt_status(&self) -> Result<InterruptStatus> {
193193
let mut interrupt_status = InterruptStatus::empty();
194194
let status = (self.get_status)(self, Some(&mut interrupt_status), None);
195-
status.into_with_val(|| interrupt_status)
195+
status.to_result_with_val(|| interrupt_status)
196196
}
197197

198198
/// Read the current recycled transmit buffer status from a
199199
/// network interface.
200200
pub fn get_recycled_transmit_buffer_status(&self) -> Result<Option<NonNull<u8>>> {
201201
let mut tx_buf: *mut c_void = ptr::null_mut();
202202
let status = (self.get_status)(self, None, Some(&mut tx_buf));
203-
status.into_with_val(|| NonNull::new(tx_buf.cast()))
203+
status.to_result_with_val(|| NonNull::new(tx_buf.cast()))
204204
}
205205

206206
/// Place a packet in the transmit queue of a network interface.
@@ -245,7 +245,7 @@ impl SimpleNetwork {
245245
dest_addr,
246246
protocol,
247247
);
248-
status.into_with_val(|| buffer_size)
248+
status.to_result_with_val(|| buffer_size)
249249
}
250250

251251
/// Event that fires once a packet is available to be received.

uefi/src/proto/pi/mp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ impl MpServices {
144144
let mut total: usize = 0;
145145
let mut enabled: usize = 0;
146146
(self.get_number_of_processors)(self, &mut total, &mut enabled)
147-
.into_with_val(|| ProcessorCount { total, enabled })
147+
.to_result_with_val(|| ProcessorCount { total, enabled })
148148
}
149149

150150
/// Gets detailed information on the requested processor at the instant this call is made.
151151
pub fn get_processor_info(&self, processor_number: usize) -> Result<ProcessorInformation> {
152152
let mut pi: ProcessorInformation = Default::default();
153-
(self.get_processor_info)(self, processor_number, &mut pi).into_with_val(|| pi)
153+
(self.get_processor_info)(self, processor_number, &mut pi).to_result_with_val(|| pi)
154154
}
155155

156156
/// Executes provided function on all APs in blocking mode.
@@ -233,6 +233,6 @@ impl MpServices {
233233
/// Gets the handle number of the caller processor.
234234
pub fn who_am_i(&self) -> Result<usize> {
235235
let mut processor_number: usize = 0;
236-
(self.who_am_i)(self, &mut processor_number).into_with_val(|| processor_number)
236+
(self.who_am_i)(self, &mut processor_number).to_result_with_val(|| processor_number)
237237
}
238238
}

uefi/src/proto/rng.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,20 @@ impl Rng {
6161
let mut algorithm_list_size = algorithm_list.len() * mem::size_of::<RngAlgorithmType>();
6262

6363
unsafe {
64-
(self.get_info)(self, &mut algorithm_list_size, algorithm_list.as_mut_ptr()).into_with(
65-
|| {
66-
let len = algorithm_list_size / mem::size_of::<RngAlgorithmType>();
67-
&algorithm_list[..len]
68-
},
69-
|status| {
70-
if status == Status::BUFFER_TOO_SMALL {
71-
Some(algorithm_list_size)
72-
} else {
73-
None
74-
}
75-
},
76-
)
64+
(self.get_info)(self, &mut algorithm_list_size, algorithm_list.as_mut_ptr())
65+
.to_result_with(
66+
|| {
67+
let len = algorithm_list_size / mem::size_of::<RngAlgorithmType>();
68+
&algorithm_list[..len]
69+
},
70+
|status| {
71+
if status == Status::BUFFER_TOO_SMALL {
72+
Some(algorithm_list_size)
73+
} else {
74+
None
75+
}
76+
},
77+
)
7778
}
7879
}
7980

uefi/src/proto/security/memory_protection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl MemoryProtection {
5656
let (base_address, length) = range_to_base_and_len(byte_region);
5757
unsafe {
5858
(self.get_memory_attributes)(self, base_address, length, &mut attributes)
59-
.into_with_val(|| attributes)
59+
.to_result_with_val(|| attributes)
6060
}
6161
}
6262

uefi/src/proto/tcg/v2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ impl Tcg {
614614
/// Get information about the protocol and TPM device.
615615
pub fn get_capability(&mut self) -> Result<BootServiceCapability> {
616616
let mut capability = BootServiceCapability::default();
617-
unsafe { (self.get_capability)(self, &mut capability).into_with_val(|| capability) }
617+
unsafe { (self.get_capability)(self, &mut capability).to_result_with_val(|| capability) }
618618
}
619619

620620
/// Get the V1 event log. This provides events in the same format as a V1
@@ -739,7 +739,7 @@ impl Tcg {
739739

740740
let status = unsafe { (self.get_active_pcr_banks)(self, &mut active_pcr_banks) };
741741

742-
status.into_with_val(|| active_pcr_banks)
742+
status.to_result_with_val(|| active_pcr_banks)
743743
}
744744

745745
/// Set the active PCR banks. Each bank corresponds to a hash
@@ -766,7 +766,7 @@ impl Tcg {
766766
(self.get_result_of_set_active_pcr_banks)(self, &mut operation_present, &mut response)
767767
};
768768

769-
status.into_with_val(|| {
769+
status.to_result_with_val(|| {
770770
if operation_present == 0 {
771771
None
772772
} else {

0 commit comments

Comments
 (0)