pub trait CommandDisplay: Display + DynClone {
    // Required methods
    fn program(&self) -> Cow<'_, str>;
    fn args(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_>;

    // Provided method
    fn program_quoted(&self) -> Cow<'_, str> { ... }
}
Expand description

A Command that can be Displayed.

The command’s program and arguments are provided as strings, which may contain � U+FFFD REPLACEMENT CHARACTER if the program or arguments cannot be decoded as UTF-8.

The Display implementation in Utf8ProgramAndArgs additionally performs shell quoting on the command’s program and args.

Required Methods§

source

fn program(&self) -> Cow<'_, str>

The command’s program name, decoded as UTF-8.

let command = Command::new("echo");
let displayed: Utf8ProgramAndArgs = (&command).into();
assert_eq!(
    displayed.program(),
    "echo",
);
source

fn args(&self) -> Box<dyn Iterator<Item = Cow<'_, str>> + '_>

The command’s arguments, decoded as UTF-8.

let mut command = Command::new("echo");
command.arg("puppy doggy");
let displayed: Utf8ProgramAndArgs = (&command).into();
assert_eq!(
    displayed.args().collect::<Vec<_>>(),
    vec!["puppy doggy"],
);

Provided Methods§

source

fn program_quoted(&self) -> Cow<'_, str>

The command’s program name, shell-quoted.

let command = Command::new("ooga booga");
let displayed: Utf8ProgramAndArgs = (&command).into();
assert_eq!(
    displayed.program_quoted(),
    "'ooga booga'",
);

Implementors§