Trait AsCommand

Source
pub trait AsCommand {
    // Required method
    fn as_command(&self) -> Command;
}
Expand description

Trait to convert various types into a Command.

Required Methods§

Source

fn as_command(&self) -> Command

Converts the implementing type into a Command.

§Returns

A Command object that can be used to run a system command.

§Example
use easy_cmd::AsCommand;
use std::process::Command;

// Define the same command using four different types.
let command_str: &str = "echo \"Hello, World!\"";
let command_string: String = String::from("echo \"Hello, World!\"");
let command_vec: Vec<&str> = vec!["echo", "Hello, World!"];
let command_slice: &[&str] = &["echo", "Hello, World!"];

// Convert them to Command objects. Note that the four Command objects will be identical.
let command_from_str = command_str.as_command();
let command_from_string = command_string.as_command();
let command_from_vec = command_vec.as_command();
let command_from_slice = command_slice.as_command();

Implementations on Foreign Types§

Source§

impl AsCommand for &str

Source§

impl AsCommand for &[&str]

Source§

impl AsCommand for &[String]

Source§

impl AsCommand for str

Source§

impl AsCommand for String

Source§

impl AsCommand for Vec<&str>

Source§

impl AsCommand for Vec<String>

Source§

impl AsCommand for [&str]

Source§

impl AsCommand for [String]

Source§

impl<const N: usize> AsCommand for [&str; N]

Source§

impl<const N: usize> AsCommand for [String; N]

Implementors§