pub trait AsCommand {
// Required method
fn as_command(&self) -> Command;
}
Expand description
Trait to convert various types into a Command
.
Required Methods§
Sourcefn as_command(&self) -> Command
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();