diff options
| author | Jokler <jokler.contact@gmail.com> | 2018-03-02 22:11:21 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2018-03-02 22:11:21 +0100 |
| commit | 0b4131e8cf91ed10f24d3faed341034d518aea53 (patch) | |
| tree | 09498ec2f2ec495a1b45a6762e61ed67f496c6f8 /src/plugin.rs | |
| parent | 0bcc7c0923852b48ebbb94ceeecc98f551fa920d (diff) | |
| download | frippy-0b4131e8cf91ed10f24d3faed341034d518aea53.tar.gz frippy-0b4131e8cf91ed10f24d3faed341034d518aea53.zip | |
Use Error & ErrorKind pair instead of simple enums
Each plugin should define its own errors with a respective variant
in the main ErrorKind of frippy.
A new procedural macro was added to reduce the boilerplate required
for new error system.
It can be used by deriving "Error" and adding a name for the Error
via the "error" attribute.
So far non of the plugins except for Url and Factoids
use their own errors yet.
Diffstat (limited to 'src/plugin.rs')
| -rw-r--r-- | src/plugin.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/plugin.rs b/src/plugin.rs index f33fa80..e57f072 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -2,16 +2,17 @@ use std::fmt; use irc::client::prelude::*; -use irc::error::IrcError; +use error::FrippyError; /// Describes if a [`Plugin`](trait.Plugin.html) is done working on a /// [`Message`](../../irc/proto/message/struct.Message.html) or if another thread is required. #[derive(Debug)] pub enum ExecutionStatus { - /// The [`Plugin`](trait.Plugin.html) does not need to do any more work on this [`Message`](../../irc/proto/message/struct.Message.html). + /// The [`Plugin`](trait.Plugin.html) does not need to do any more work on this + /// [`Message`](../../irc/proto/message/struct.Message.html). Done, /// An error occured during the execution. - Err(Box<IrcError>), + Err(FrippyError), /// The execution needs to be done by [`execute_threaded()`](trait.Plugin.html#tymethod.execute_threaded). RequiresThread, } @@ -19,15 +20,17 @@ pub enum ExecutionStatus { /// `Plugin` has to be implemented for any struct that should be usable /// as a `Plugin` in frippy. pub trait Plugin: PluginName + Send + Sync + fmt::Debug { - /// Handles messages which are not commands or returns [`RequiresThread`](enum.ExecutionStatus.html#variant.RequiresThread) + /// Handles messages which are not commands or returns + /// [`RequiresThread`](enum.ExecutionStatus.html#variant.RequiresThread) /// if [`execute_threaded()`](trait.Plugin.html#tymethod.execute_threaded) should be used instead. - fn execute(&self, server: &IrcClient, message: &Message) -> ExecutionStatus; + fn execute(&self, client: &IrcClient, message: &Message) -> ExecutionStatus; /// Handles messages which are not commands in a new thread. - fn execute_threaded(&self, server: &IrcClient, message: &Message) -> Result<(), IrcError>; + fn execute_threaded(&self, client: &IrcClient, message: &Message) -> Result<(), FrippyError>; /// Handles any command directed at this plugin. - fn command(&self, server: &IrcClient, command: PluginCommand) -> Result<(), IrcError>; - /// Similar to [`command()`](trait.Plugin.html#tymethod.command) but return a String instead of sending messages directly to IRC. - fn evaluate(&self, server: &IrcClient, command: PluginCommand) -> Result<String, String>; + fn command(&self, client: &IrcClient, command: PluginCommand) -> Result<(), FrippyError>; + /// Similar to [`command()`](trait.Plugin.html#tymethod.command) but return a String instead of + /// sending messages directly to IRC. + fn evaluate(&self, client: &IrcClient, command: PluginCommand) -> Result<String, String>; } /// `PluginName` is required by [`Plugin`](trait.Plugin.html). |
