Skip to main content

Command

Struct Command 

Source
pub struct Command<'a> {
    pub command_pattern: CommandPattern<'a>,
    pub arguments: Vec<String>,
    pub options: Options,
}
Expand description

Command generated from an appropriate defined CommandPattern. It stores information of the result command based on Args, therefore Command is a result type, and not a container.

§Fields

  • command_patterns: Original CommandPattern from which this Command was generated. It is stored in order to call its callback field and to determine which command was matched.
  • arguments: Arguments generated following CommandPattern’s args_count field.
  • options: Options generated following CommandPattern’s option_patterns field.

§Example

Command::new(
    Args::CommandLineArgs,
    &[
        CommandPattern::new(
            "exit",
            &[], // No arguments are accepted.
            &[], // No options are accepted.
            &|_, _| std::process:exit(0),
        ),
    ],
)

Fields§

§command_pattern: CommandPattern<'a>§arguments: Vec<String>§options: Options

Implementations§

Source§

impl<'a> Command<'a>

Source

pub fn from_args( args: Args, command_patterns: &[CommandPattern<'a>], ) -> Result<Self, String>

Creates a new Command from commandargs’s Args.

§Fields
  • args: Source of arguments used, refer to Args to know the possible variants that can be passed here.
  • command_patterns: Accepted CommandPattern’s used to get a result Command.
§Example
Command::from_args(
    Args::CommandLineArgs,
    &[
        CommandPattern::new(
            "exit",
            &[], // No arguments are accepted.
            &[], // No options are accepted.
            &|_, _| std::process:exit(0),
        ),
    ],
)
Source

pub fn execute(&'a self)

Execute the result command, by calling the callback field of the matched CommandPattern.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Command<'a>

§

impl<'a> !Send for Command<'a>

§

impl<'a> !Sync for Command<'a>

§

impl<'a> !UnwindSafe for Command<'a>

§

impl<'a> Freeze for Command<'a>

§

impl<'a> Unpin for Command<'a>

§

impl<'a> UnsafeUnpin for Command<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.