From 1b6b67b3322d40feb90d5f2112ffdf7dcbd16dd4 Mon Sep 17 00:00:00 2001 From: lumi Date: Sat, 27 May 2017 19:40:00 +0200 Subject: [PATCH] simplify plugin code --- src/client.rs | 4 ++-- src/component.rs | 4 ++-- src/plugin.rs | 2 +- src/plugin_macro.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client.rs b/src/client.rs index 88537e6..a4504a0 100644 --- a/src/client.rs +++ b/src/client.rs @@ -103,7 +103,7 @@ impl ClientBuilder { pub struct Client { jid: Jid, transport: Arc>, - plugins: HashMap>>, + plugins: HashMap>, binding: PluginProxyBinding, dispatcher: Arc, } @@ -118,7 +118,7 @@ impl Client { pub fn register_plugin(&mut self, mut plugin: P) { let binding = self.binding.clone(); plugin.bind(binding); - let p = Arc::new(Box::new(plugin) as Box); + let p = Arc::new(plugin) as Arc; P::init(&self.dispatcher, p.clone()); if self.plugins.insert(TypeId::of::

(), p).is_some() { panic!("registering a plugin that's already registered"); diff --git a/src/component.rs b/src/component.rs index 3f7c61e..77de6c0 100644 --- a/src/component.rs +++ b/src/component.rs @@ -84,7 +84,7 @@ impl ComponentBuilder { pub struct Component { jid: Jid, transport: Arc>, - plugins: HashMap>>, + plugins: HashMap>, binding: PluginProxyBinding, dispatcher: Arc, } @@ -99,7 +99,7 @@ impl Component { pub fn register_plugin(&mut self, mut plugin: P) { let binding = self.binding.clone(); plugin.bind(binding); - let p = Arc::new(Box::new(plugin) as Box); + let p = Arc::new(plugin) as Arc; P::init(&self.dispatcher, p.clone()); if self.plugins.insert(TypeId::of::

(), p).is_some() { panic!("registering a plugin that's already registered"); diff --git a/src/plugin.rs b/src/plugin.rs index 295da16..ac495ba 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -90,7 +90,7 @@ pub trait Plugin: Any + PluginAny { } pub trait PluginInit { - fn init(dispatcher: &Dispatcher, me: Arc>); + fn init(dispatcher: &Dispatcher, me: Arc); } pub trait PluginAny { diff --git a/src/plugin_macro.rs b/src/plugin_macro.rs index 2d8e034..9a289c4 100644 --- a/src/plugin_macro.rs +++ b/src/plugin_macro.rs @@ -10,7 +10,7 @@ macro_rules! impl_plugin { #[allow(unused_variables)] impl $crate::plugin::PluginInit for $plugin { fn init( dispatcher: &$crate::event::Dispatcher - , me: ::std::sync::Arc>) { + , me: ::std::sync::Arc<$crate::plugin::Plugin>) { $( let new_arc = me.clone(); dispatcher.register($pri, move |e: &$evt| {