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 @@
1414//! The config options created here will be alive as long as the plugin is
1515//! loaded so they don't need to be freed manually. The drop implementation of
1616//! the section will do so.
17use crate::{MatrixServer, Servers, ServersHandle};
17use crate::{MatrixServer, Servers};
1818use weechat::config::{
1919 Conf, ConfigSection, ConfigSectionSettings, OptionChanged,
2020 SectionReadCallback,
@@ -22,7 +22,7 @@ use weechat::config::{
2222use weechat::Weechat;
2323
2424use std::cell::{Ref, RefCell, RefMut};
25use std::rc::{Rc, Weak};
25use std::rc::Rc;
2626
2727#[derive(Clone)]
2828pub struct Config {
@@ -30,12 +30,6 @@ pub struct Config {
3030 servers: Servers,
3131}
3232
33#[derive(Clone, Default)]
34pub struct ConfigHandle {
35 inner: Weak<RefCell<weechat::config::Config>>,
36 servers: ServersHandle,
37}
38
3933impl SectionReadCallback for Config {
4034 fn callback(
4135 &mut self,
@@ -79,18 +73,6 @@ impl SectionReadCallback for Config {
7973 }
8074}
8175
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
9476impl Config {
9577 pub fn new(_weechat: &Weechat, servers: &Servers) -> Config {
9678 let config = Weechat::config_new("matrix-rust")
@@ -131,11 +113,4 @@ impl Config {
131113 pub fn borrow_mut(&self) -> RefMut<'_, weechat::config::Config> {
132114 self.inner.borrow_mut()
133115 }
134
135 pub fn clone_weak(&self) -> ConfigHandle {
136 ConfigHandle {
137 inner: Rc::downgrade(&self.inner),
138 servers: self.servers.clone_weak(),
139 }
140 }
141116}
src/lib.rs +1 −16
@@ -8,11 +8,9 @@ mod server;
88
99use std::cell::{Ref, RefCell, RefMut};
1010use std::collections::HashMap;
11use std::rc::{Rc, Weak};
11use std::rc::Rc;
1212use tracing_subscriber;
1313
14use tokio::sync::mpsc::unbounded_channel;
15
1614use weechat::{weechat_plugin, ArgsWeechat, Weechat, WeechatPlugin};
1715
1816use crate::commands::Commands;
@@ -24,15 +22,6 @@ const PLUGIN_NAME: &str = "matrix";
2422#[derive(Clone)]
2523pub struct Servers(Rc<RefCell<HashMap<String, MatrixServer>>>);
2624
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
3625impl Servers {
3726 fn new() -> Self {
3827 Servers(Rc::new(RefCell::new(HashMap::new())))
@@ -45,10 +34,6 @@ impl Servers {
4534 fn borrow_mut(&self) -> RefMut<'_, HashMap<String, MatrixServer>> {
4635 self.0.borrow_mut()
4736 }
48
49 fn clone_weak(&self) -> ServersHandle {
50 ServersHandle(Rc::downgrade(&self.0))
51 }
5237}
5338
5439struct Matrix {