pub trait CommandArgument<S, A> {
    fn parse<'a>(
        &self,
        source: S,
        input: &'a str
    ) -> IResult<&'a str, A, CommandError<'a>>; }
Expand description

A parser for a command argument type.

This trait is implemented by all argument types. Implementors must not account for starting or ending spaces. It is a good idea to use as many nom combinators as possible here.

Example

use brigadier_rs::CommandError;
use brigadier_rs::CommandArgument;

pub struct BoolArgument;

impl CommandArgument<(), bool> for BoolArgument {
    fn parse<'a>(&self, source: (), input: &'a str) -> IResult<&'a str, bool, CommandError<'a>> {
        alt((
            |i| {
                let (i, _) = tag_no_case("true")(i)?;
                Ok((i, true))
            },
            |i| {
                let (i, _) = tag_no_case("false")(i)?;
                Ok((i, false))
            },
        ))(input)
    }
}

Required Methods

Where the magic happens! This is what ends up extracting type A from the raw string input.

Note

Do not let this function return a Failure!! Doing so is not recommended and will most likely cause unwanted side-effects elsewhere.

Example
let parser = literal::<()>("foo"); // new literal argument parser

assert_eq!(("", ()), parser.parse((), "foo").unwrap()); // `LiteralArgument` implements `CommandArgument<()>`

Implementors