diff options
| author | Jokler <jokler.contact@gmail.com> | 2017-10-10 17:48:30 +0200 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2017-10-11 15:41:32 +0200 |
| commit | 0195219d5c0b0ff1486b3e6bdcd62a807d3d2932 (patch) | |
| tree | 0e518f025de563a9df792ad8237275d3ad71af5d /src/plugin.rs | |
| parent | ec33c870852f8a52f3cc0cf5a84b99c775dee1e3 (diff) | |
| download | frippy-0195219d5c0b0ff1486b3e6bdcd62a807d3d2932.tar.gz frippy-0195219d5c0b0ff1486b3e6bdcd62a807d3d2932.zip | |
Create plugin_derive to replace the register_plugin macro
Diffstat (limited to 'src/plugin.rs')
| -rw-r--r-- | src/plugin.rs | 29 |
1 files changed, 5 insertions, 24 deletions
diff --git a/src/plugin.rs b/src/plugin.rs index 3791bf1..0a4034d 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -2,38 +2,19 @@ use std::fmt; use irc::client::prelude::*; use irc::error::Error as IrcError; -pub trait Plugin: Send + Sync + fmt::Display + fmt::Debug { +pub trait Plugin: PluginName + Send + Sync + fmt::Debug { fn is_allowed(&self, server: &IrcServer, message: &Message) -> bool; fn execute(&mut self, server: &IrcServer, message: &Message) -> Result<(), IrcError>; fn command(&mut self, server: &IrcServer, command: PluginCommand) -> Result<(), IrcError>; } +pub trait PluginName: Send + Sync + fmt::Debug { + fn name(&self) -> &str; +} + #[derive(Clone, Debug)] pub struct PluginCommand { pub source: String, pub target: String, pub tokens: Vec<String>, } - -macro_rules! register_plugin { - ($t:ident) => { - use std::fmt; - - #[derive(Debug)] - pub struct $t { - _name: &'static str, - } - - impl fmt::Display for $t { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self._name) - } - } - - impl $t { - pub fn new() -> $t { - $t { _name: stringify!($t) } - } - } - }; -} |
