Trait Command

Source
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§

Source

fn name() -> &'static str

Provides the name of the command to be matched. Examples include PRIVMSG or PING.

Source

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§

Source

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.

Implementors§

Source§

impl<'a> Command<'a> for Created<'a>

Source§

impl<'a> Command<'a> for EndNamesReply<'a>

Source§

impl<'a> Command<'a> for NamesReply<'a>

Source§

impl<'a> Command<'a> for Ping<'a>

Source§

impl<'a> Command<'a> for Pong<'a>

Source§

impl<'a> Command<'a> for PrivMsg<'a>

Source§

impl<'a> Command<'a> for ServerInfo<'a>

Source§

impl<'a> Command<'a> for Welcome<'a>

Source§

impl<'a> Command<'a> for YourHost<'a>