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§
Sourcefn matches(arg: &str) -> bool
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.
Sourcefn from_arg(
arg: &'a str,
args: &mut ArgumentTraverser<'a>,
context: &C,
) -> Result<Self, Error>
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§
Sourcefn partial_matches(partial_arg: &str) -> bool
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.