@@ -14,6 +14,7 @@ use core::cell::UnsafeCell;
14
14
use core:: ffi:: c_void;
15
15
use core:: fmt:: { Debug , Formatter } ;
16
16
use core:: mem:: { self , MaybeUninit } ;
17
+ use core:: ops:: { Deref , DerefMut } ;
17
18
use core:: ptr:: NonNull ;
18
19
use core:: { ptr, slice} ;
19
20
@@ -884,6 +885,8 @@ impl BootServices {
884
885
)
885
886
. into_with_val ( || unsafe {
886
887
let interface = P :: mut_ptr_from_ffi ( interface) as * const UnsafeCell < P > ;
888
+
889
+ #[ allow( deprecated) ]
887
890
ScopedProtocol {
888
891
interface : & * interface,
889
892
open_params : params,
@@ -1030,21 +1033,17 @@ impl BootServices {
1030
1033
} ,
1031
1034
OpenProtocolAttributes :: Exclusive ,
1032
1035
) ?;
1033
- let loaded_image = unsafe { & * loaded_image. interface . get ( ) } ;
1034
-
1035
- let device_handle = loaded_image. device ( ) ;
1036
1036
1037
1037
let device_path = self . open_protocol :: < DevicePath > (
1038
1038
OpenProtocolParams {
1039
- handle : device_handle ,
1039
+ handle : loaded_image . device ( ) ,
1040
1040
agent : image_handle,
1041
1041
controller : None ,
1042
1042
} ,
1043
1043
OpenProtocolAttributes :: Exclusive ,
1044
1044
) ?;
1045
- let mut device_path = unsafe { & * device_path. interface . get ( ) } ;
1046
1045
1047
- let device_handle = self . locate_device_path :: < SimpleFileSystem > ( & mut device_path) ?;
1046
+ let device_handle = self . locate_device_path :: < SimpleFileSystem > ( & mut & * device_path) ?;
1048
1047
1049
1048
self . open_protocol :: < SimpleFileSystem > (
1050
1049
OpenProtocolParams {
@@ -1330,6 +1329,7 @@ pub struct OpenProtocolParams {
1330
1329
/// protocol and why [`UnsafeCell`] is used.
1331
1330
pub struct ScopedProtocol < ' a , P : Protocol + ?Sized > {
1332
1331
/// The protocol interface.
1332
+ #[ deprecated( since = "0.16.0" , note = "use Deref and DerefMut instead" ) ]
1333
1333
pub interface : & ' a UnsafeCell < P > ,
1334
1334
1335
1335
open_params : OpenProtocolParams ,
@@ -1353,6 +1353,26 @@ impl<'a, P: Protocol + ?Sized> Drop for ScopedProtocol<'a, P> {
1353
1353
}
1354
1354
}
1355
1355
1356
+ impl < ' a , P : Protocol + ?Sized > Deref for ScopedProtocol < ' a , P > {
1357
+ type Target = P ;
1358
+
1359
+ fn deref ( & self ) -> & Self :: Target {
1360
+ #[ allow( deprecated) ]
1361
+ unsafe {
1362
+ & * self . interface . get ( )
1363
+ }
1364
+ }
1365
+ }
1366
+
1367
+ impl < ' a , P : Protocol + ?Sized > DerefMut for ScopedProtocol < ' a , P > {
1368
+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
1369
+ #[ allow( deprecated) ]
1370
+ unsafe {
1371
+ & mut * self . interface . get ( )
1372
+ }
1373
+ }
1374
+ }
1375
+
1356
1376
/// Type of allocation to perform.
1357
1377
#[ derive( Debug , Copy , Clone ) ]
1358
1378
pub enum AllocateType {
0 commit comments