[][src]Struct cmd_parser::CommandParser

pub struct CommandParser { /* fields omitted */ }

Implementations

impl CommandParser[src]

pub fn new() -> Self[src]

Creates a new instance of CommandParser.

Example

let mut parser = cmd_parser::CommandParser::new();

pub fn insert(
    &mut self,
    name: &str,
    cmd: fn(_: Vec<&str>)
) -> Result<(), &'static str>
[src]

Adds a function to the system.

Example

fn echo(args: Vec<&str>) {
    println!("{}", args[1..].concat());
}

let mut parser = cmd_parser::CommandParser::new();
parser.insert("echo", echo);

pub fn call(&mut self, cmd: &str) -> Result<(), &'static str>[src]

Calls a function with a command string.

Example

let mut parser = cmd_parser::CommandParser::new();
parser.insert("echo", |x| println!("{}", x[1..].concat()));

parser.call("echo This is an example!");

pub fn call_args(&mut self, cmd: Vec<&str>) -> Result<(), &'static str>[src]

Calls a function with an array of components of the command.

Example

let mut parser = cmd_parser::CommandParser::new();
parser.insert("echo", |x| println!("{}", x[1..].concat()));

parser.call_args(vec!["echo", "This is an example"]);

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.