pub trait Command<'a> {
// Required methods
fn name() -> &'static str;
fn parse(arguments: ArgumentIter<'a>) -> Option<Self>
where Self: Sized;
// Provided method
fn try_match(command: &str, arguments: ArgumentIter<'a>) -> Option<Self>
where Self: Sized { ... }
}
Expand description
The Command
trait is a trait that’s implemented by types wishing to provide command
parsing capability for usage with the Message::command
method.
Required Methods§
Sourcefn name() -> &'static str
fn name() -> &'static str
Provides the name of the command to be matched. Examples include PRIVMSG
or PING
.
Sourcefn parse(arguments: ArgumentIter<'a>) -> Option<Self>where
Self: Sized,
fn parse(arguments: ArgumentIter<'a>) -> Option<Self>where
Self: Sized,
This method takes in an iterator of arguments associated with a Message
and attempts
to parse the arguments into a matched Command
. If no match is found, None is returned.
Provided Methods§
Sourcefn try_match(command: &str, arguments: ArgumentIter<'a>) -> Option<Self>where
Self: Sized,
fn try_match(command: &str, arguments: ArgumentIter<'a>) -> Option<Self>where
Self: Sized,
A default implementation that takes in the given command name and arguments and attempts to match
the command and parse the arguments into a strongly typed representation. If there is no match
or the parse fails, it returns None
.
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.