Commit c18143d14a
Unsigned
Layout: unified · split
src/config.rs +2 −27
| @@ -14,7 +14,7 @@ | ||
| 14 | 14 | //! The config options created here will be alive as long as the plugin is |
| 15 | 15 | //! loaded so they don't need to be freed manually. The drop implementation of |
| 16 | 16 | //! the section will do so. |
| 17 | use crate::{MatrixServer, Servers, ServersHandle}; | |
| 17 | use crate::{MatrixServer, Servers}; | |
| 18 | 18 | use weechat::config::{ |
| 19 | 19 | Conf, ConfigSection, ConfigSectionSettings, OptionChanged, |
| 20 | 20 | SectionReadCallback, |
| @@ -22,7 +22,7 @@ use weechat::config::{ | ||
| 22 | 22 | use weechat::Weechat; |
| 23 | 23 | |
| 24 | 24 | use std::cell::{Ref, RefCell, RefMut}; |
| 25 | use std::rc::{Rc, Weak}; | |
| 25 | use std::rc::Rc; | |
| 26 | 26 | |
| 27 | 27 | #[derive(Clone)] |
| 28 | 28 | pub struct Config { |
| @@ -30,12 +30,6 @@ pub struct Config { | ||
| 30 | 30 | servers: Servers, |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | #[derive(Clone, Default)] | |
| 34 | pub struct ConfigHandle { | |
| 35 | inner: Weak<RefCell<weechat::config::Config>>, | |
| 36 | servers: ServersHandle, | |
| 37 | } | |
| 38 | ||
| 39 | 33 | impl SectionReadCallback for Config { |
| 40 | 34 | fn callback( |
| 41 | 35 | &mut self, |
| @@ -79,18 +73,6 @@ impl SectionReadCallback for Config { | ||
| 79 | 73 | } |
| 80 | 74 | } |
| 81 | 75 | |
| 82 | impl ConfigHandle { | |
| 83 | pub fn upgrade(&self) -> Config { | |
| 84 | Config { | |
| 85 | inner: self | |
| 86 | .inner | |
| 87 | .upgrade() | |
| 88 | .expect("Config got deleted before plugin unload"), | |
| 89 | servers: self.servers.upgrade(), | |
| 90 | } | |
| 91 | } | |
| 92 | } | |
| 93 | ||
| 94 | 76 | impl Config { |
| 95 | 77 | pub fn new(_weechat: &Weechat, servers: &Servers) -> Config { |
| 96 | 78 | let config = Weechat::config_new("matrix-rust") |
| @@ -131,11 +113,4 @@ impl Config { | ||
| 131 | 113 | pub fn borrow_mut(&self) -> RefMut<'_, weechat::config::Config> { |
| 132 | 114 | self.inner.borrow_mut() |
| 133 | 115 | } |
| 134 | ||
| 135 | pub fn clone_weak(&self) -> ConfigHandle { | |
| 136 | ConfigHandle { | |
| 137 | inner: Rc::downgrade(&self.inner), | |
| 138 | servers: self.servers.clone_weak(), | |
| 139 | } | |
| 140 | } | |
| 141 | 116 | } |
src/lib.rs +1 −16
| @@ -8,11 +8,9 @@ mod server; | ||
| 8 | 8 | |
| 9 | 9 | use std::cell::{Ref, RefCell, RefMut}; |
| 10 | 10 | use std::collections::HashMap; |
| 11 | use std::rc::{Rc, Weak}; | |
| 11 | use std::rc::Rc; | |
| 12 | 12 | use tracing_subscriber; |
| 13 | 13 | |
| 14 | use tokio::sync::mpsc::unbounded_channel; | |
| 15 | ||
| 16 | 14 | use weechat::{weechat_plugin, ArgsWeechat, Weechat, WeechatPlugin}; |
| 17 | 15 | |
| 18 | 16 | use crate::commands::Commands; |
| @@ -24,15 +22,6 @@ const PLUGIN_NAME: &str = "matrix"; | ||
| 24 | 22 | #[derive(Clone)] |
| 25 | 23 | pub struct Servers(Rc<RefCell<HashMap<String, MatrixServer>>>); |
| 26 | 24 | |
| 27 | #[derive(Clone, Default)] | |
| 28 | pub struct ServersHandle(Weak<RefCell<HashMap<String, MatrixServer>>>); | |
| 29 | ||
| 30 | impl ServersHandle { | |
| 31 | fn upgrade(&self) -> Servers { | |
| 32 | Servers(self.0.upgrade().expect("Severs are dropped?")) | |
| 33 | } | |
| 34 | } | |
| 35 | ||
| 36 | 25 | impl Servers { |
| 37 | 26 | fn new() -> Self { |
| 38 | 27 | Servers(Rc::new(RefCell::new(HashMap::new()))) |
| @@ -45,10 +34,6 @@ impl Servers { | ||
| 45 | 34 | fn borrow_mut(&self) -> RefMut<'_, HashMap<String, MatrixServer>> { |
| 46 | 35 | self.0.borrow_mut() |
| 47 | 36 | } |
| 48 | ||
| 49 | fn clone_weak(&self) -> ServersHandle { | |
| 50 | ServersHandle(Rc::downgrade(&self.0)) | |
| 51 | } | |
| 52 | 37 | } |
| 53 | 38 | |
| 54 | 39 | struct Matrix { |