@@ -4,11 +4,10 @@ use crate::env::current_exe;
44use crate :: ffi:: OsString ;
55use crate :: iter:: Iterator ;
66use crate :: sys:: pal:: helpers;
7- use crate :: { fmt, vec} ;
87
9- pub struct Args {
10- parsed_args_list : vec :: IntoIter < OsString > ,
11- }
8+ # [ path = "common.rs" ]
9+ mod common ;
10+ pub use common :: Args ;
1211
1312pub fn args ( ) -> Args {
1413 let lazy_current_exe = || Vec :: from ( [ current_exe ( ) . map ( Into :: into) . unwrap_or_default ( ) ] ) ;
@@ -22,51 +21,17 @@ pub fn args() -> Args {
2221 let lp_size = unsafe { ( * protocol. as_ptr ( ) ) . load_options_size } as usize ;
2322 // Break if we are sure that it cannot be UTF-16
2423 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 ( ) ) ;
2625 }
2726 let lp_size = lp_size / size_of :: < u16 > ( ) ;
2827
2928 let lp_cmd_line = unsafe { ( * protocol. as_ptr ( ) ) . load_options as * const u16 } ;
3029 if !lp_cmd_line. is_aligned ( ) {
31- return Args { parsed_args_list : lazy_current_exe ( ) . into_iter ( ) } ;
30+ return Args :: new ( lazy_current_exe ( ) ) ;
3231 }
3332 let lp_cmd_line = unsafe { crate :: slice:: from_raw_parts ( lp_cmd_line, lp_size) } ;
3433
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) )
7035}
7136
7237/// Implements the UEFI command-line argument parsing algorithm.
0 commit comments