1 //! `ShellParams` protocol
2 
3 use crate::proto::unsafe_protocol;
4 use crate::{data_types, Char16};
5 use core::slice::from_raw_parts;
6 use uefi_raw::protocol::shell_params::ShellParametersProtocol;
7 
8 use crate::CStr16;
9 
10 /// The ShellParameters protocol.
11 #[derive(Debug)]
12 #[repr(transparent)]
13 #[unsafe_protocol(ShellParametersProtocol::GUID)]
14 pub struct ShellParameters(ShellParametersProtocol);
15 
16 impl ShellParameters {
17     /// Get the number of shell parameter arguments
18     #[must_use]
args_len(&self) -> usize19     pub const fn args_len(&self) -> usize {
20         self.0.argc
21     }
22 
23     /// Get an iterator of the shell parameter arguments
args(&self) -> impl Iterator<Item = &CStr16>24     pub fn args(&self) -> impl Iterator<Item = &CStr16> {
25         self.args_slice()
26             .iter()
27             .map(|x| unsafe { CStr16::from_ptr(*x) })
28     }
29 
30     /// Get a slice of the args, as Char16 pointers
31     #[must_use]
args_slice(&self) -> &[*const Char16]32     const fn args_slice(&self) -> &[*const Char16] {
33         unsafe {
34             from_raw_parts(
35                 self.0.argv.cast::<*const data_types::chars::Char16>(),
36                 self.0.argc,
37             )
38         }
39     }
40 }
41