Skip to content

Commit 45ce231

Browse files
committed
Implemented clippy suggestions + header fix
1 parent db5e1b9 commit 45ce231

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
13
use uefi::proto::shell::Shell;
24
use uefi::{CStr16, boot};
35
use uefi_raw::Status;
@@ -7,7 +9,7 @@ pub fn test() {
79

810
let handle = boot::get_handle_for_protocol::<Shell>().expect("No Shell handles");
911

10-
let mut shell =
12+
let shell =
1113
boot::open_protocol_exclusive::<Shell>(handle).expect("Failed to open Shell protocol");
1214

1315
// create some files
@@ -23,7 +25,7 @@ pub fn test() {
2325
.vec()
2426
.unwrap();
2527
assert_eq!(
26-
*cur_env_vec.get(0).unwrap(),
28+
*cur_env_vec.first().unwrap(),
2729
CStr16::from_str_with_buf("path", &mut test_buf).unwrap()
2830
);
2931
assert_eq!(
@@ -32,7 +34,7 @@ pub fn test() {
3234
);
3335

3436
let path_val = shell
35-
.get_env(Some(cur_env_vec.get(0).unwrap()))
37+
.get_env(Some(cur_env_vec.first().unwrap()))
3638
.expect("Could not get path")
3739
.val()
3840
.unwrap();

uefi/src/proto/shell/mod.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
13
//! EFI Shell Protocol v2.2
24
35
#![cfg(feature = "alloc")]
@@ -109,6 +111,7 @@ pub enum EnvOutput<'a> {
109111

110112
impl<'a> EnvOutput<'a> {
111113
/// Extracts the env var value from EnvOutput
114+
#[must_use]
112115
pub fn val(self) -> Option<&'a CStr16> {
113116
match self {
114117
EnvOutput::Val(v) => Some(v),
@@ -117,6 +120,7 @@ impl<'a> EnvOutput<'a> {
117120
}
118121

119122
/// Extracts the vector of variable names from EnvOutput
123+
#[must_use]
120124
pub fn vec(self) -> Option<Vec<&'a CStr16>> {
121125
match self {
122126
EnvOutput::Vec(v) => Some(v),
@@ -140,7 +144,7 @@ impl Shell {
140144

141145
let cl_ptr = command_line.as_ptr();
142146
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();
144148

145149
(self.execute)(&parent_image, cl_ptr, env_ptr, out_status.as_mut_ptr())
146150
.to_result_with_val(|| out_status.assume_init())
@@ -152,19 +156,20 @@ impl Shell {
152156
/// # Arguments
153157
///
154158
/// * `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
158162
///
159163
/// # Returns
160164
///
161165
/// * `Some(env_value)` - Value of the environment variable
162166
/// * `Some(Vec<env_names>)` - Vector of environment variable names
163167
/// * `None` - Environment variable doesn't exist
168+
#[must_use]
164169
pub fn get_env<'a>(&'a self, name: Option<&CStr16>) -> Option<EnvOutput<'a>> {
165170
match name {
166171
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();
168173
let var_val = (self.get_env)(name_ptr);
169174
if var_val.is_null() {
170175
None
@@ -213,14 +218,14 @@ impl Shell {
213218
/// * `name` - The environment variable for which to set the value
214219
/// * `value` - The new value of the environment variable
215220
/// * `volatile` - Indicates whether or not the variable is volatile or
216-
/// not
221+
/// not
217222
///
218223
/// # Returns
219224
///
220225
/// * `Status::SUCCESS` The variable was successfully set
221226
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();
224229
(self.set_env)(name_ptr, value_ptr, volatile)
225230
}
226231

@@ -229,7 +234,7 @@ impl Shell {
229234
/// # Arguments
230235
///
231236
/// * `file_system_mapping` - The file system mapping for which to get
232-
/// the current directory
237+
/// the current directory
233238
/// # Returns
234239
///
235240
/// * `Some(cwd)` - CStr16 containing the current working directory
@@ -251,7 +256,7 @@ impl Shell {
251256
///
252257
/// * `file_system` - Pointer to the file system's mapped name.
253258
/// * `directory` - Points to the directory on the device specified by
254-
/// `file_system`.
259+
/// `file_system`.
255260
/// # Returns
256261
///
257262
/// * `Status::SUCCESS` The directory was successfully set
@@ -296,7 +301,7 @@ impl Shell {
296301
/// * `file_name` - Name of the file to be created (null terminated)
297302
/// * `file_attribs` - Attributes of the new file
298303
/// * `file_handle` - On return, points to the created file/directory's
299-
/// handle
304+
/// handle
300305
pub fn create_file(&self, file_name: &CStr16, file_attribs: u64) -> Result<ShellFileHandle> {
301306
// TODO: Find out how we could take a &str instead, or maybe AsRef<str>, though I think it needs `alloc`
302307
// the returned handle can possibly be NULL, so we need to wrap `ShellFileHandle` in an `Option`
@@ -362,10 +367,10 @@ impl Shell {
362367
/// # Returns
363368
///
364369
/// * `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.
366371
/// * `Ok(None)` - if no files were found that match the given pattern.
367372
/// * `Err(e)` - if an error occurred while searching for files. The specific error variants
368-
/// are described below.
373+
/// are described below.
369374
///
370375
/// # Errors
371376
///
@@ -428,7 +433,7 @@ pub struct ShellFileInfo {
428433
impl ShellFileInfo {
429434
/// TODO
430435
#[must_use]
431-
pub fn file_name(&self) -> &CStr16 {
436+
pub const fn file_name(&self) -> &CStr16 {
432437
unsafe { &*self.file_name }
433438
}
434439
}
@@ -480,7 +485,7 @@ impl<'l> Iterator for FileListIter<'l> {
480485
}
481486
}
482487

483-
impl<'l> DoubleEndedIterator for FileListIter<'l> {
488+
impl DoubleEndedIterator for FileListIter<'_> {
484489
fn next_back(&mut self) -> Option<Self::Item> {
485490
if self.current_node == self.current_node_back {
486491
None
@@ -532,7 +537,7 @@ impl<'a> FileList<'a> {
532537
/// Returns the first element of the file list
533538
#[must_use]
534539
#[inline]
535-
pub fn first(&'a self) -> &'a ShellFileInfo {
540+
pub const fn first(&'a self) -> &'a ShellFileInfo {
536541
// safety: once `self` is created, start is valid
537542
unsafe { &*self.start.cast() }
538543
}
@@ -549,7 +554,7 @@ impl<'a> FileList<'a> {
549554
/// The end position is lazily generated on the first call to this function.
550555
#[must_use]
551556
#[inline]
552-
pub fn last(&'a self) -> &'a ShellFileInfo {
557+
pub const fn last(&'a self) -> &'a ShellFileInfo {
553558
if !self.end.is_null() {
554559
unsafe { &*self.end.cast() }
555560
} else {
@@ -569,7 +574,7 @@ impl<'a> FileList<'a> {
569574
}
570575
}
571576

572-
impl<'a> Drop for FileList<'a> {
577+
impl Drop for FileList<'_> {
573578
fn drop(&mut self) {
574579
let mut root = self.start as *mut ListEntry;
575580
let file_list_ptr = &mut root as *mut *mut ListEntry;

0 commit comments

Comments
 (0)