Trait FromArgument

Source
pub trait FromArgument<'a, C>: Sized {
    // Required methods
    fn matches(arg: &str) -> bool;
    fn from_arg(
        arg: &'a str,
        args: &mut ArgumentTraverser<'a>,
        context: &C,
    ) -> Result<Self, Error>;

    // Provided method
    fn partial_matches(partial_arg: &str) -> bool { ... }
}
Expand description

Trait for matching and converting string arguments to concrete types. Any type which implements this trait can be used as a node type in a command module.

Required Methods§

Source

fn matches(arg: &str) -> bool

Returns whether or not the given argument matches the format of Self. Returning true does not imply that from_arg will succeed, but it does imply that the argument could succeed given the correct context. In other words, this function should return true for any input that is in the set of all possible string representations of Self given all possible contexts. If Self is represented by multiple arguments, then this function should return true if the first of those arguments is valid.

Source

fn from_arg( arg: &'a str, args: &mut ArgumentTraverser<'a>, context: &C, ) -> Result<Self, Error>

Parses the given argument given a context. This function should only fail if it is impossible to construct a valid Self from the given string, traverser, and context. Any logical checks should be performed in execution blocks.

Note that it is not recommended to grab additional arguments from the given traverser. If the traverser is advanced, then suggestion generation will stop after this argument is visited.

Provided Methods§

Source

fn partial_matches(partial_arg: &str) -> bool

This function follows similar rules to matches, however it is not guaranteed that a full argument will be given to this function. This test is primarily used in suggestion generation while the user is part-way through typing an argument, and hence should return true whenever matches returns true, and should also return true for every truncation of every input for which matches returns true.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a, C> FromArgument<'a, C> for &'a str

Source§

fn matches(_arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for bool

Source§

fn matches(arg: &str) -> bool

Source§

fn partial_matches(partial_arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for char

Source§

fn matches(arg: &str) -> bool

Source§

fn partial_matches(partial_arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for f32

Source§

fn matches(arg: &str) -> bool

Source§

fn partial_matches(partial_arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for f64

Source§

fn matches(arg: &str) -> bool

Source§

fn partial_matches(partial_arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for i8

Source§

fn matches(arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for i16

Source§

fn matches(arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for i32

Source§

fn matches(arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for i64

Source§

fn matches(arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for i128

Source§

fn matches(arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for isize

Source§

fn matches(arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for u8

Source§

fn matches(arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for u16

Source§

fn matches(arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for u32

Source§

fn matches(arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for u64

Source§

fn matches(arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for u128

Source§

fn matches(arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for usize

Source§

fn matches(arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C> FromArgument<'a, C> for String

Source§

fn matches(_arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, _args: &mut ArgumentTraverser<'a>, _ctx: &C, ) -> Result<Self, Error>

Source§

impl<'a, C, T> FromArgument<'a, C> for Option<T>
where T: FromArgument<'a, C>,

Source§

fn matches(arg: &str) -> bool

Source§

fn partial_matches(partial_arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, args: &mut ArgumentTraverser<'a>, context: &C, ) -> Result<Self, Error>

Source§

impl<'a, C, T> FromArgument<'a, C> for Box<T>
where T: FromArgument<'a, C>,

Source§

fn matches(arg: &str) -> bool

Source§

fn partial_matches(partial_arg: &str) -> bool

Source§

fn from_arg( arg: &'a str, args: &mut ArgumentTraverser<'a>, context: &C, ) -> Result<Self, Error>

Implementors§

Source§

impl<'a, C> FromArgument<'a, C> for Help<'a>