Skip to content

Commit 86f82fa

Browse files
committed
uefi: rename DevicePath[Node]::{to_string -> to_string16}()
This is a pre-requisite for the next commit that implements Display. Display comes with a to_string() method already.
1 parent cf7a4bb commit 86f82fa

6 files changed

Lines changed: 27 additions & 20 deletions

File tree

uefi-test-runner/src/proto/device_path.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn test_device_path_to_string() {
107107
let path = create_test_device_path();
108108

109109
let to_text =
110-
|display_only, allow_shortcuts| path.to_string(display_only, allow_shortcuts).unwrap();
110+
|display_only, allow_shortcuts| path.to_string16(display_only, allow_shortcuts).unwrap();
111111

112112
assert_eq!(
113113
&*to_text(DisplayOnly(true), AllowShortcuts(true)),
@@ -167,7 +167,7 @@ fn test_device_path_node_to_string() {
167167
let nodes: Vec<_> = path.node_iter().collect();
168168

169169
let to_text = |node: &DevicePathNode, display_only, allow_shortcuts| {
170-
node.to_string(display_only, allow_shortcuts).unwrap()
170+
node.to_string16(display_only, allow_shortcuts).unwrap()
171171
};
172172

173173
assert_eq!(
@@ -229,20 +229,20 @@ fn test_device_path_append() {
229229
let node = path.node_iter().next().unwrap();
230230

231231
assert_eq!(
232-
path.to_string(DisplayOnly(false), AllowShortcuts(false))
232+
path.to_string16(DisplayOnly(false), AllowShortcuts(false))
233233
.unwrap(),
234234
cstr16!("Ata(Primary,Master,0x1)/VenMsg(E0C14753-F9BE-11D2-9A0C-0090273FC14D)")
235235
);
236236
assert_eq!(
237-
node.to_string(DisplayOnly(false), AllowShortcuts(false))
237+
node.to_string16(DisplayOnly(false), AllowShortcuts(false))
238238
.unwrap(),
239239
cstr16!("Ata(Primary,Master,0x1)")
240240
);
241241

242242
assert_eq!(
243243
path.append_path(&path2)
244244
.unwrap()
245-
.to_string(DisplayOnly(false), AllowShortcuts(false))
245+
.to_string16(DisplayOnly(false), AllowShortcuts(false))
246246
.unwrap(),
247247
cstr16!(
248248
"Ata(Primary,Master,0x1)/VenMsg(E0C14753-F9BE-11D2-9A0C-0090273FC14D)/Ata(Primary,Master,0x1)/VenMsg(E0C14753-F9BE-11D2-9A0C-0090273FC14D)"
@@ -251,7 +251,7 @@ fn test_device_path_append() {
251251
assert_eq!(
252252
path.append_node(node)
253253
.unwrap()
254-
.to_string(DisplayOnly(false), AllowShortcuts(false))
254+
.to_string16(DisplayOnly(false), AllowShortcuts(false))
255255
.unwrap(),
256256
cstr16!(
257257
"Ata(Primary,Master,0x1)/VenMsg(E0C14753-F9BE-11D2-9A0C-0090273FC14D)/Ata(Primary,Master,0x1)"

uefi-test-runner/src/proto/network/http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn print_handle_devpath(prefix: &str, handle: &Handle) {
1515
info!("{prefix}no device path for handle");
1616
return;
1717
};
18-
if let Ok(string) = dp.to_string(DisplayOnly(true), AllowShortcuts(true)) {
18+
if let Ok(string) = dp.to_string16(DisplayOnly(true), AllowShortcuts(true)) {
1919
info!("{prefix}{string}");
2020
}
2121
}

uefi-test-runner/src/proto/nvme/pass_thru.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn has_nvme_drive() -> bool {
2727
};
2828
let nvme_pt = boot::open_protocol_exclusive::<NvmePassThru>(nvme_pt_handle).unwrap();
2929
let device_path_str = device_path
30-
.to_string(DisplayOnly(true), AllowShortcuts(false))
30+
.to_string16(DisplayOnly(true), AllowShortcuts(false))
3131
.unwrap();
3232
info!("- Successfully opened NVMe: {device_path_str}");
3333
let mut nvme_ctrl = nvme_pt.controller();

uefi-test-runner/src/proto/pci/root_bridge.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn test() {
4545
let subclass_code = ((reg1 >> 16) & 0xFF) as u8;
4646
let device_path = pci_tree.device_path(&root_device_path, addr).unwrap();
4747
let device_path_str = device_path
48-
.to_string(DisplayOnly(false), AllowShortcuts(false))
48+
.to_string16(DisplayOnly(false), AllowShortcuts(false))
4949
.unwrap()
5050
.to_string();
5151

@@ -81,7 +81,7 @@ pub fn test() {
8181
for scsi_handle in scsi_handles {
8282
let device_path = get_open_protocol::<DevicePath>(scsi_handle);
8383
let device_path = device_path
84-
.to_string(DisplayOnly(false), AllowShortcuts(false))
84+
.to_string16(DisplayOnly(false), AllowShortcuts(false))
8585
.unwrap()
8686
.to_string();
8787
assert!(mass_storage_dev_paths.contains(&device_path));

uefi/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
- **Breaking:** `boot::check_event` now consumes `&Event` rather than `Event`, removing the
2929
need for unnecessary `Event::unsafe_clone()`s.
3030
- MSRV increased to 1.88.
31+
- **Breaking:** Renamed `DevicePath::to_string()` to `DevicePath::to_string16()`
32+
to better differentiate with the new `to_string()` coming from the new
33+
`Display`.
34+
- **Breaking:** Renamed `DevicePathNode::to_string()` to `DevicePathNode::to_string16()`
35+
to better differentiate with the new `to_string()` coming from the new
36+
`Display`.
3137

3238
# uefi - v0.36.1 (2025-11-05)
3339

uefi/src/proto/device_path/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,10 @@ impl DevicePathNode {
301301
DevicePathNodeEnum::try_from(self)
302302
}
303303

304-
/// Transforms the device path node to its string representation using the
305-
/// [`DevicePathToText`] protocol.
304+
/// Transforms the device path node to an owned UEFI string ([`CString16`])
305+
/// using the [`DevicePathToText`] protocol.
306306
#[cfg(feature = "alloc")]
307-
pub fn to_string(
307+
pub fn to_string16(
308308
&self,
309309
display_only: DisplayOnly,
310310
allow_shortcuts: AllowShortcuts,
@@ -460,7 +460,7 @@ impl ToOwned for DevicePathInstance {
460460
/// = open_protocol_exclusive::<DevicePath>(device_handle).unwrap();
461461
/// log::debug!(
462462
/// "Device path: {}",
463-
/// device_path.to_string(DisplayOnly(true), AllowShortcuts(true)).unwrap()
463+
/// device_path.to_string16(DisplayOnly(true), AllowShortcuts(true)).unwrap()
464464
/// );
465465
/// }
466466
/// ```
@@ -598,10 +598,11 @@ impl DevicePath {
598598
.map_err(|_| DevicePathUtilitiesError::OutOfMemory)
599599
}
600600

601-
/// Transforms the device path to its string representation using the
602-
/// [`DevicePathToText`] protocol.
601+
/// Transforms the device path to an owned UEFI string ([`CString16`])
602+
/// using the [`DevicePathToText`] protocol.
603603
#[cfg(feature = "alloc")]
604-
pub fn to_string(
604+
// to_string() comes from Display and produces a Rust string.
605+
pub fn to_string16(
605606
&self,
606607
display_only: DisplayOnly,
607608
allow_shortcuts: AllowShortcuts,
@@ -831,9 +832,9 @@ impl Deref for LoadedImageDevicePath {
831832
}
832833

833834
/// Errors that may happen when a device path is transformed to a string
834-
/// representation using:
835-
/// - [`DevicePath::to_string`]
836-
/// - [`DevicePathNode::to_string`]
835+
/// using:
836+
/// - [`DevicePath::to_string16`]
837+
/// - [`DevicePathNode::to_string16`]
837838
#[derive(Debug)]
838839
pub enum DevicePathToTextError {
839840
/// Can't locate a handle buffer with handles associated with the

0 commit comments

Comments
 (0)