From 0195219d5c0b0ff1486b3e6bdcd62a807d3d2932 Mon Sep 17 00:00:00 2001 From: Jokler Date: Tue, 10 Oct 2017 17:48:30 +0200 Subject: Create plugin_derive to replace the register_plugin macro --- src/plugin.rs | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) (limited to 'src/plugin.rs') 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, } - -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) } - } - } - }; -} -- cgit v1.2.3-70-g09d2