1
+ // SPDX-License-Identifier: MIT OR Apache-2.0
2
+
1
3
//! EFI Shell Protocol v2.2
2
4
3
5
#![ cfg( feature = "alloc" ) ]
@@ -109,6 +111,7 @@ pub enum EnvOutput<'a> {
109
111
110
112
impl < ' a > EnvOutput < ' a > {
111
113
/// Extracts the env var value from EnvOutput
114
+ #[ must_use]
112
115
pub fn val ( self ) -> Option < & ' a CStr16 > {
113
116
match self {
114
117
EnvOutput :: Val ( v) => Some ( v) ,
@@ -117,6 +120,7 @@ impl<'a> EnvOutput<'a> {
117
120
}
118
121
119
122
/// Extracts the vector of variable names from EnvOutput
123
+ #[ must_use]
120
124
pub fn vec ( self ) -> Option < Vec < & ' a CStr16 > > {
121
125
match self {
122
126
EnvOutput :: Vec ( v) => Some ( v) ,
@@ -140,7 +144,7 @@ impl Shell {
140
144
141
145
let cl_ptr = command_line. as_ptr ( ) ;
142
146
unsafe {
143
- let env_ptr: * const * const Char16 = ( & ( * environment. as_ptr ( ) ) . as_ptr ( ) ) . cast ( ) ;
147
+ let env_ptr: * const * const Char16 = ( * environment. as_ptr ( ) ) . as_ptr ( ) . cast ( ) ;
144
148
145
149
( self . execute ) ( & parent_image, cl_ptr, env_ptr, out_status. as_mut_ptr ( ) )
146
150
. to_result_with_val ( || out_status. assume_init ( ) )
@@ -152,19 +156,20 @@ impl Shell {
152
156
/// # Arguments
153
157
///
154
158
/// * `name` - The environment variable name of which to retrieve the
155
- /// value
156
- /// If None, will return all defined shell environment
157
- /// variables
159
+ /// value
160
+ /// If None, will return all defined shell environment
161
+ /// variables
158
162
///
159
163
/// # Returns
160
164
///
161
165
/// * `Some(env_value)` - Value of the environment variable
162
166
/// * `Some(Vec<env_names>)` - Vector of environment variable names
163
167
/// * `None` - Environment variable doesn't exist
168
+ #[ must_use]
164
169
pub fn get_env < ' a > ( & ' a self , name : Option < & CStr16 > ) -> Option < EnvOutput < ' a > > {
165
170
match name {
166
171
Some ( n) => {
167
- let name_ptr: * const Char16 = ( n as * const CStr16 ) . cast ( ) ;
172
+ let name_ptr: * const Char16 = core :: ptr :: from_ref :: < CStr16 > ( n ) . cast ( ) ;
168
173
let var_val = ( self . get_env ) ( name_ptr) ;
169
174
if var_val. is_null ( ) {
170
175
None
@@ -213,14 +218,14 @@ impl Shell {
213
218
/// * `name` - The environment variable for which to set the value
214
219
/// * `value` - The new value of the environment variable
215
220
/// * `volatile` - Indicates whether or not the variable is volatile or
216
- /// not
221
+ /// not
217
222
///
218
223
/// # Returns
219
224
///
220
225
/// * `Status::SUCCESS` The variable was successfully set
221
226
pub fn set_env ( & self , name : & CStr16 , value : & CStr16 , volatile : bool ) -> Status {
222
- let name_ptr: * const Char16 = ( name as * const CStr16 ) . cast ( ) ;
223
- let value_ptr: * const Char16 = ( value as * const CStr16 ) . cast ( ) ;
227
+ let name_ptr: * const Char16 = core :: ptr :: from_ref :: < CStr16 > ( name) . cast ( ) ;
228
+ let value_ptr: * const Char16 = core :: ptr :: from_ref :: < CStr16 > ( value) . cast ( ) ;
224
229
( self . set_env ) ( name_ptr, value_ptr, volatile)
225
230
}
226
231
@@ -229,7 +234,7 @@ impl Shell {
229
234
/// # Arguments
230
235
///
231
236
/// * `file_system_mapping` - The file system mapping for which to get
232
- /// the current directory
237
+ /// the current directory
233
238
/// # Returns
234
239
///
235
240
/// * `Some(cwd)` - CStr16 containing the current working directory
@@ -251,7 +256,7 @@ impl Shell {
251
256
///
252
257
/// * `file_system` - Pointer to the file system's mapped name.
253
258
/// * `directory` - Points to the directory on the device specified by
254
- /// `file_system`.
259
+ /// `file_system`.
255
260
/// # Returns
256
261
///
257
262
/// * `Status::SUCCESS` The directory was successfully set
@@ -296,7 +301,7 @@ impl Shell {
296
301
/// * `file_name` - Name of the file to be created (null terminated)
297
302
/// * `file_attribs` - Attributes of the new file
298
303
/// * `file_handle` - On return, points to the created file/directory's
299
- /// handle
304
+ /// handle
300
305
pub fn create_file ( & self , file_name : & CStr16 , file_attribs : u64 ) -> Result < ShellFileHandle > {
301
306
// TODO: Find out how we could take a &str instead, or maybe AsRef<str>, though I think it needs `alloc`
302
307
// the returned handle can possibly be NULL, so we need to wrap `ShellFileHandle` in an `Option`
@@ -362,10 +367,10 @@ impl Shell {
362
367
/// # Returns
363
368
///
364
369
/// * `Ok(Some(file_iter))` - if one or more files were found that match the given pattern,
365
- /// where `file_iter` is an iterator over the matching files.
370
+ /// where `file_iter` is an iterator over the matching files.
366
371
/// * `Ok(None)` - if no files were found that match the given pattern.
367
372
/// * `Err(e)` - if an error occurred while searching for files. The specific error variants
368
- /// are described below.
373
+ /// are described below.
369
374
///
370
375
/// # Errors
371
376
///
@@ -428,7 +433,7 @@ pub struct ShellFileInfo {
428
433
impl ShellFileInfo {
429
434
/// TODO
430
435
#[ must_use]
431
- pub fn file_name ( & self ) -> & CStr16 {
436
+ pub const fn file_name ( & self ) -> & CStr16 {
432
437
unsafe { & * self . file_name }
433
438
}
434
439
}
@@ -480,7 +485,7 @@ impl<'l> Iterator for FileListIter<'l> {
480
485
}
481
486
}
482
487
483
- impl < ' l > DoubleEndedIterator for FileListIter < ' l > {
488
+ impl DoubleEndedIterator for FileListIter < ' _ > {
484
489
fn next_back ( & mut self ) -> Option < Self :: Item > {
485
490
if self . current_node == self . current_node_back {
486
491
None
@@ -532,7 +537,7 @@ impl<'a> FileList<'a> {
532
537
/// Returns the first element of the file list
533
538
#[ must_use]
534
539
#[ inline]
535
- pub fn first ( & ' a self ) -> & ' a ShellFileInfo {
540
+ pub const fn first ( & ' a self ) -> & ' a ShellFileInfo {
536
541
// safety: once `self` is created, start is valid
537
542
unsafe { & * self . start . cast ( ) }
538
543
}
@@ -549,7 +554,7 @@ impl<'a> FileList<'a> {
549
554
/// The end position is lazily generated on the first call to this function.
550
555
#[ must_use]
551
556
#[ inline]
552
- pub fn last ( & ' a self ) -> & ' a ShellFileInfo {
557
+ pub const fn last ( & ' a self ) -> & ' a ShellFileInfo {
553
558
if !self . end . is_null ( ) {
554
559
unsafe { & * self . end . cast ( ) }
555
560
} else {
@@ -569,7 +574,7 @@ impl<'a> FileList<'a> {
569
574
}
570
575
}
571
576
572
- impl < ' a > Drop for FileList < ' a > {
577
+ impl Drop for FileList < ' _ > {
573
578
fn drop ( & mut self ) {
574
579
let mut root = self . start as * mut ListEntry ;
575
580
let file_list_ptr = & mut root as * mut * mut ListEntry ;
0 commit comments