@@ -217,27 +217,24 @@ impl DevicePathNode {
217
217
218
218
/// Transforms the device path node to its string representation using the
219
219
/// [`DevicePathToText`] protocol.
220
- ///
221
- /// The resulting string is only None, if there was not enough memory.
222
220
#[ cfg( feature = "alloc" ) ]
223
221
pub fn to_string (
224
222
& self ,
225
223
bs : & BootServices ,
226
224
display_only : DisplayOnly ,
227
225
allow_shortcuts : AllowShortcuts ,
228
- ) -> Result < Option < CString16 > , DevicePathToTextError > {
226
+ ) -> Result < CString16 , DevicePathToTextError > {
229
227
let to_text_protocol = open_text_protocol ( bs) ?;
230
228
231
- let cstring16 = to_text_protocol
229
+ to_text_protocol
232
230
. convert_device_node_to_text ( bs, self , display_only, allow_shortcuts)
233
- . ok ( )
234
231
. map ( |pool_string| {
235
232
let cstr16 = & * pool_string;
236
233
// Another allocation; pool string is dropped. This overhead
237
234
// is negligible. CString16 is more convenient to use.
238
235
CString16 :: from ( cstr16)
239
- } ) ;
240
- Ok ( cstring16 )
236
+ } )
237
+ . map_err ( |_| DevicePathToTextError :: OutOfMemory )
241
238
}
242
239
}
243
240
@@ -430,27 +427,24 @@ impl DevicePath {
430
427
431
428
/// Transforms the device path to its string representation using the
432
429
/// [`DevicePathToText`] protocol.
433
- ///
434
- /// The resulting string is only None, if there was not enough memory.
435
430
#[ cfg( feature = "alloc" ) ]
436
431
pub fn to_string (
437
432
& self ,
438
433
bs : & BootServices ,
439
434
display_only : DisplayOnly ,
440
435
allow_shortcuts : AllowShortcuts ,
441
- ) -> Result < Option < CString16 > , DevicePathToTextError > {
436
+ ) -> Result < CString16 , DevicePathToTextError > {
442
437
let to_text_protocol = open_text_protocol ( bs) ?;
443
438
444
- let cstring16 = to_text_protocol
439
+ to_text_protocol
445
440
. convert_device_path_to_text ( bs, self , display_only, allow_shortcuts)
446
- . ok ( )
447
441
. map ( |pool_string| {
448
442
let cstr16 = & * pool_string;
449
443
// Another allocation; pool string is dropped. This overhead
450
444
// is negligible. CString16 is more convenient to use.
451
445
CString16 :: from ( cstr16)
452
- } ) ;
453
- Ok ( cstring16 )
446
+ } )
447
+ . map_err ( |_| DevicePathToTextError :: OutOfMemory )
454
448
}
455
449
}
456
450
@@ -789,6 +783,8 @@ pub enum DevicePathToTextError {
789
783
/// The handle supporting the [`DevicePathToText`] protocol exists but it
790
784
/// could not be opened.
791
785
CantOpenProtocol ( crate :: Error ) ,
786
+ /// Failed to allocate pool memory.
787
+ OutOfMemory ,
792
788
}
793
789
794
790
impl Display for DevicePathToTextError {
0 commit comments