@@ -4,11 +4,10 @@ use crate::env::current_exe;
4
4
use crate :: ffi:: OsString ;
5
5
use crate :: iter:: Iterator ;
6
6
use crate :: sys:: pal:: helpers;
7
- use crate :: { fmt, vec} ;
8
7
9
- pub struct Args {
10
- parsed_args_list : vec :: IntoIter < OsString > ,
11
- }
8
+ # [ path = "common.rs" ]
9
+ mod common ;
10
+ pub use common :: Args ;
12
11
13
12
pub fn args ( ) -> Args {
14
13
let lazy_current_exe = || Vec :: from ( [ current_exe ( ) . map ( Into :: into) . unwrap_or_default ( ) ] ) ;
@@ -22,51 +21,17 @@ pub fn args() -> Args {
22
21
let lp_size = unsafe { ( * protocol. as_ptr ( ) ) . load_options_size } as usize ;
23
22
// Break if we are sure that it cannot be UTF-16
24
23
if lp_size < size_of :: < u16 > ( ) || lp_size % size_of :: < u16 > ( ) != 0 {
25
- return Args { parsed_args_list : lazy_current_exe ( ) . into_iter ( ) } ;
24
+ return Args :: new ( lazy_current_exe ( ) ) ;
26
25
}
27
26
let lp_size = lp_size / size_of :: < u16 > ( ) ;
28
27
29
28
let lp_cmd_line = unsafe { ( * protocol. as_ptr ( ) ) . load_options as * const u16 } ;
30
29
if !lp_cmd_line. is_aligned ( ) {
31
- return Args { parsed_args_list : lazy_current_exe ( ) . into_iter ( ) } ;
30
+ return Args :: new ( lazy_current_exe ( ) ) ;
32
31
}
33
32
let lp_cmd_line = unsafe { crate :: slice:: from_raw_parts ( lp_cmd_line, lp_size) } ;
34
33
35
- Args {
36
- parsed_args_list : parse_lp_cmd_line ( lp_cmd_line)
37
- . unwrap_or_else ( lazy_current_exe)
38
- . into_iter ( ) ,
39
- }
40
- }
41
-
42
- impl fmt:: Debug for Args {
43
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
44
- self . parsed_args_list . as_slice ( ) . fmt ( f)
45
- }
46
- }
47
-
48
- impl Iterator for Args {
49
- type Item = OsString ;
50
-
51
- fn next ( & mut self ) -> Option < OsString > {
52
- self . parsed_args_list . next ( )
53
- }
54
-
55
- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
56
- self . parsed_args_list . size_hint ( )
57
- }
58
- }
59
-
60
- impl ExactSizeIterator for Args {
61
- fn len ( & self ) -> usize {
62
- self . parsed_args_list . len ( )
63
- }
64
- }
65
-
66
- impl DoubleEndedIterator for Args {
67
- fn next_back ( & mut self ) -> Option < OsString > {
68
- self . parsed_args_list . next_back ( )
69
- }
34
+ Args :: new ( parse_lp_cmd_line ( lp_cmd_line) . unwrap_or_else ( lazy_current_exe) )
70
35
}
71
36
72
37
/// Implements the UEFI command-line argument parsing algorithm.
0 commit comments