CommandArgument

Trait CommandArgument 

Source
pub trait CommandArgument<S, A> {
    // Required method
    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§

Source

fn parse<'a>( &self, source: S, input: &'a str, ) -> IResult<&'a str, A, CommandError<'a>>

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§

Source§

impl<A, C, S> CommandArgument<S, ()> for LiteralExecutor<A, C, S>
where A: CommandArgument<S, ()>,

Source§

impl<A, E, C, O, S> CommandArgument<S, O> for ThenExecutor<A, E, C, O, S>
where A: CommandArgument<S, O>,

Source§

impl<A, E, C, S> CommandArgument<S, ()> for LiteralThenExecutor<A, E, C, S>
where A: CommandArgument<S, ()>,

Source§

impl<A, E, O, S> CommandArgument<S, O> for CommandThen<A, E, O, S>
where A: CommandArgument<S, O>,

Source§

impl<A, E, S> CommandArgument<S, ()> for LiteralThen<A, E, S>
where A: CommandArgument<S, ()>,

Source§

impl<A, O, C, S> CommandArgument<S, O> for DefaultExecutor<A, O, C, S>
where A: CommandArgument<S, O>,

Source§

impl<S> CommandArgument<S, bool> for BoolArgument<S>

Source§

impl<S> CommandArgument<S, ()> for LiteralArgument<S>

Source§

impl<S, E> CommandArgument<S, UsagePrint<<E as IntoMultipleUsage>::Item>> for HelpArgument<S, E>

Source§

impl<S, N> CommandArgument<S, N> for NumberArgument<N, S>
where N: PartialOrd,