uefi: process: Add CommandArgs support · model-checking/verify-rust-std@afe1ef0 (original) (raw)

`@@ -4,7 +4,6 @@ use crate::ffi::OsStr;

`

4

4

`use crate::ffi::OsString;

`

5

5

`use crate::fmt;

`

6

6

`use crate::io;

`

7

``

`-

use crate:📑:PhantomData;

`

8

7

`use crate::num::NonZero;

`

9

8

`use crate::num::NonZeroI32;

`

10

9

`use crate::path::Path;

`

`@@ -23,7 +22,7 @@ use super::helpers;

`

23

22

``

24

23

`pub struct Command {

`

25

24

`prog: OsString,

`

26

``

`-

args: OsString,

`

``

25

`+

args: Vec,

`

27

26

`stdout: Option,

`

28

27

`stderr: Option,

`

29

28

`}

`

`@@ -48,15 +47,14 @@ impl Command {

`

48

47

`pub fn new(program: &OsStr) -> Command {

`

49

48

`Command {

`

50

49

`prog: program.to_os_string(),

`

51

``

`-

args: program.to_os_string(),

`

``

50

`+

args: Vec::from([program.to_os_string()]),

`

52

51

`stdout: None,

`

53

52

`stderr: None,

`

54

53

`}

`

55

54

`}

`

56

55

``

57

56

`pub fn arg(&mut self, arg: &OsStr) {

`

58

``

`-

self.args.push(" ");

`

59

``

`-

self.args.push(arg);

`

``

57

`+

self.args.push(arg.to_os_string());

`

60

58

`}

`

61

59

``

62

60

`pub fn env_mut(&mut self) -> &mut CommandEnv {

`

`@@ -80,11 +78,11 @@ impl Command {

`

80

78

`}

`

81

79

``

82

80

`pub fn get_program(&self) -> &OsStr {

`

83

``

`-

panic!("unsupported")

`

``

81

`+

self.prog.as_ref()

`

84

82

`}

`

85

83

``

86

84

`pub fn get_args(&self) -> CommandArgs<'_> {

`

87

``

`-

panic!("unsupported")

`

``

85

`+

CommandArgs { iter: self.args.iter() }

`

88

86

`}

`

89

87

``

90

88

`pub fn get_envs(&self) -> CommandEnvs<'_> {

`

`@@ -153,8 +151,15 @@ impl Command {

`

153

151

`None => cmd.stderr_inherit(),

`

154

152

`};

`

155

153

``

156

``

`-

if !self.args.is_empty() {

`

157

``

`-

cmd.set_args(&self.args);

`

``

154

`+

if self.args.len() > 1 {

`

``

155

`+

let args = self.args.iter().fold(OsString::new(), |mut acc, arg| {

`

``

156

`+

if !acc.is_empty() {

`

``

157

`+

acc.push(" ");

`

``

158

`+

}

`

``

159

`+

acc.push(arg);

`

``

160

`+

acc

`

``

161

`+

});

`

``

162

`+

cmd.set_args(&args);

`

158

163

`}

`

159

164

``

160

165

`let stat = cmd.start_image()?;

`

`@@ -293,24 +298,31 @@ impl Process {

`

293

298

`}

`

294

299

``

295

300

`pub struct CommandArgs<'a> {

`

296

``

`-

_p: PhantomData<&'a ()>,

`

``

301

`+

iter: crate::slice::Iter<'a, OsString>,

`

297

302

`}

`

298

303

``

299

304

`impl<'a> Iterator for CommandArgs<'a> {

`

300

305

`type Item = &'a OsStr;

`

301

306

`fn next(&mut self) -> Option<&'a OsStr> {

`

302

``

`-

None

`

``

307

`+

self.iter.next().map(|x| x.as_ref())

`

303

308

`}

`

304

309

`fn size_hint(&self) -> (usize, Option) {

`

305

``

`-

(0, Some(0))

`

``

310

`+

self.iter.size_hint()

`

306

311

`}

`

307

312

`}

`

308

313

``

309

``

`-

impl<'a> ExactSizeIterator for CommandArgs<'a> {}

`

``

314

`+

impl<'a> ExactSizeIterator for CommandArgs<'a> {

`

``

315

`+

fn len(&self) -> usize {

`

``

316

`+

self.iter.len()

`

``

317

`+

}

`

``

318

`+

fn is_empty(&self) -> bool {

`

``

319

`+

self.iter.is_empty()

`

``

320

`+

}

`

``

321

`+

}

`

310

322

``

311

323

`impl<'a> fmt::Debug for CommandArgs<'a> {

`

312

324

`fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

`

313

``

`-

f.debug_list().finish()

`

``

325

`+

f.debug_list().entries(self.iter.clone()).finish()

`

314

326

`}

`

315

327

`}

`

316

328

``