From 41fbca6f768b0bad18639ebb431b64386d9cd01e Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Fri, 24 Oct 2025 19:11:17 -0700 Subject: [PATCH] fix(utils): clarify that the to_string().contains() is necessary due to CString16 --- src/utils.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 5d79fd6..1179df9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -27,6 +27,12 @@ pub fn text_to_device_path(path: &str) -> Result { .context("unable to convert text to device path") } +/// Checks if a [CString16] contains a char `c`. +/// We need to call to_string() because CString16 doesn't support `contains` with a char. +fn cstring16_contains_char(string: &CString16, c: char) -> bool { + string.to_string().contains(c) +} + /// Grabs the root part of the `path`. /// For example, given "PciRoot(0x0)/Pci(0x4,0x0)/NVMe(0x1,00-00-00-00-00-00-00-00)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\EFI\BOOT\BOOTX64.efi" /// it will give "PciRoot(0x0)/Pci(0x4,0x0)/NVMe(0x1,00-00-00-00-00-00-00-00)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)" @@ -37,7 +43,7 @@ pub fn device_path_root(path: &DevicePath) -> Result { let item = item.to_string(DisplayOnly(false), AllowShortcuts(false)); if item .as_ref() - .map(|item| item.to_string().contains('(')) + .map(|item| cstring16_contains_char(item, '(')) .unwrap_or(false) { Some(item.unwrap_or_default()) @@ -62,7 +68,7 @@ pub fn device_path_subpath(path: &DevicePath) -> Result { let item = item.to_string(DisplayOnly(false), AllowShortcuts(false)); if item .as_ref() - .map(|item| item.to_string().contains('(')) + .map(|item| cstring16_contains_char(item, '(')) .unwrap_or(false) { None