Commit c18143d14a

c18143d14a04b7f29f5bbd2ccaaad01003528f82

parent: c5dc1a8ebc

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-04-29 16:36 UTC

weechat-matrix: Remove the config/server handles.

Layout: unified · split

src/config.rs +2 −27
@@ -14,7 +14,7 @@
14//! The config options created here will be alive as long as the plugin is 14//! The config options created here will be alive as long as the plugin is
15//! loaded so they don't need to be freed manually. The drop implementation of 15//! loaded so they don't need to be freed manually. The drop implementation of
16//! the section will do so. 16//! the section will do so.
17use crate::{MatrixServer, Servers, ServersHandle}; 17use crate::{MatrixServer, Servers};
18use weechat::config::{ 18use weechat::config::{
19 Conf, ConfigSection, ConfigSectionSettings, OptionChanged, 19 Conf, ConfigSection, ConfigSectionSettings, OptionChanged,
20 SectionReadCallback, 20 SectionReadCallback,
@@ -22,7 +22,7 @@ use weechat::config::{
22use weechat::Weechat; 22use weechat::Weechat;
23 23
24use std::cell::{Ref, RefCell, RefMut}; 24use std::cell::{Ref, RefCell, RefMut};
25use std::rc::{Rc, Weak}; 25use std::rc::Rc;
26 26
27#[derive(Clone)] 27#[derive(Clone)]
28pub struct Config { 28pub struct Config {
@@ -30,12 +30,6 @@ pub struct Config {
30 servers: Servers, 30 servers: Servers,
31} 31}
32 32
33#[derive(Clone, Default)]
34pub struct ConfigHandle {
35 inner: Weak<RefCell<weechat::config::Config>>,
36 servers: ServersHandle,
37}
38
39impl SectionReadCallback for Config { 33impl SectionReadCallback for Config {
40 fn callback( 34 fn callback(
41 &mut self, 35 &mut self,
@@ -79,18 +73,6 @@ impl SectionReadCallback for Config {
79 } 73 }
80} 74}
81 75
82impl 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
94impl Config { 76impl Config {
95 pub fn new(_weechat: &Weechat, servers: &Servers) -> Config { 77 pub fn new(_weechat: &Weechat, servers: &Servers) -> Config {
96 let config = Weechat::config_new("matrix-rust") 78 let config = Weechat::config_new("matrix-rust")
@@ -131,11 +113,4 @@ impl Config {
131 pub fn borrow_mut(&self) -> RefMut<'_, weechat::config::Config> { 113 pub fn borrow_mut(&self) -> RefMut<'_, weechat::config::Config> {
132 self.inner.borrow_mut() 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
9use std::cell::{Ref, RefCell, RefMut}; 9use std::cell::{Ref, RefCell, RefMut};
10use std::collections::HashMap; 10use std::collections::HashMap;
11use std::rc::{Rc, Weak}; 11use std::rc::Rc;
12use tracing_subscriber; 12use tracing_subscriber;
13 13
14use tokio::sync::mpsc::unbounded_channel;
15
16use weechat::{weechat_plugin, ArgsWeechat, Weechat, WeechatPlugin}; 14use weechat::{weechat_plugin, ArgsWeechat, Weechat, WeechatPlugin};
17 15
18use crate::commands::Commands; 16use crate::commands::Commands;
@@ -24,15 +22,6 @@ const PLUGIN_NAME: &str = "matrix";
24#[derive(Clone)] 22#[derive(Clone)]
25pub struct Servers(Rc<RefCell<HashMap<String, MatrixServer>>>); 23pub struct Servers(Rc<RefCell<HashMap<String, MatrixServer>>>);
26 24
27#[derive(Clone, Default)]
28pub struct ServersHandle(Weak<RefCell<HashMap<String, MatrixServer>>>);
29
30impl ServersHandle {
31 fn upgrade(&self) -> Servers {
32 Servers(self.0.upgrade().expect("Severs are dropped?"))
33 }
34}
35
36impl Servers { 25impl Servers {
37 fn new() -> Self { 26 fn new() -> Self {
38 Servers(Rc::new(RefCell::new(HashMap::new()))) 27 Servers(Rc::new(RefCell::new(HashMap::new())))
@@ -45,10 +34,6 @@ impl Servers {
45 fn borrow_mut(&self) -> RefMut<'_, HashMap<String, MatrixServer>> { 34 fn borrow_mut(&self) -> RefMut<'_, HashMap<String, MatrixServer>> {
46 self.0.borrow_mut() 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
54struct Matrix { 39struct Matrix {