mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
simplify plugin code
This commit is contained in:
parent
1550c52552
commit
1b6b67b332
4 changed files with 6 additions and 6 deletions
|
@ -103,7 +103,7 @@ impl ClientBuilder {
|
|||
pub struct Client {
|
||||
jid: Jid,
|
||||
transport: Arc<Mutex<SslTransport>>,
|
||||
plugins: HashMap<TypeId, Arc<Box<Plugin>>>,
|
||||
plugins: HashMap<TypeId, Arc<Plugin>>,
|
||||
binding: PluginProxyBinding,
|
||||
dispatcher: Arc<Dispatcher>,
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ impl Client {
|
|||
pub fn register_plugin<P: Plugin + PluginInit + 'static>(&mut self, mut plugin: P) {
|
||||
let binding = self.binding.clone();
|
||||
plugin.bind(binding);
|
||||
let p = Arc::new(Box::new(plugin) as Box<Plugin>);
|
||||
let p = Arc::new(plugin) as Arc<Plugin>;
|
||||
P::init(&self.dispatcher, p.clone());
|
||||
if self.plugins.insert(TypeId::of::<P>(), p).is_some() {
|
||||
panic!("registering a plugin that's already registered");
|
||||
|
|
|
@ -84,7 +84,7 @@ impl ComponentBuilder {
|
|||
pub struct Component {
|
||||
jid: Jid,
|
||||
transport: Arc<Mutex<PlainTransport>>,
|
||||
plugins: HashMap<TypeId, Arc<Box<Plugin>>>,
|
||||
plugins: HashMap<TypeId, Arc<Plugin>>,
|
||||
binding: PluginProxyBinding,
|
||||
dispatcher: Arc<Dispatcher>,
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ impl Component {
|
|||
pub fn register_plugin<P: Plugin + PluginInit + 'static>(&mut self, mut plugin: P) {
|
||||
let binding = self.binding.clone();
|
||||
plugin.bind(binding);
|
||||
let p = Arc::new(Box::new(plugin) as Box<Plugin>);
|
||||
let p = Arc::new(plugin) as Arc<Plugin>;
|
||||
P::init(&self.dispatcher, p.clone());
|
||||
if self.plugins.insert(TypeId::of::<P>(), p).is_some() {
|
||||
panic!("registering a plugin that's already registered");
|
||||
|
|
|
@ -90,7 +90,7 @@ pub trait Plugin: Any + PluginAny {
|
|||
}
|
||||
|
||||
pub trait PluginInit {
|
||||
fn init(dispatcher: &Dispatcher, me: Arc<Box<Plugin>>);
|
||||
fn init(dispatcher: &Dispatcher, me: Arc<Plugin>);
|
||||
}
|
||||
|
||||
pub trait PluginAny {
|
||||
|
|
|
@ -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<Box<$crate::plugin::Plugin>>) {
|
||||
, me: ::std::sync::Arc<$crate::plugin::Plugin>) {
|
||||
$(
|
||||
let new_arc = me.clone();
|
||||
dispatcher.register($pri, move |e: &$evt| {
|
||||
|
|
Loading…
Reference in a new issue