[fractal/ui-refactor: 16/16] Remove Rc<RefCell<T>> pattern in widgets::members_list




commit 0393a2ce5eb3008a8642b6372a1bfcf643764819
Author: Alejandro Domínguez <adomu net-c com>
Date:   Wed Nov 18 23:37:52 2020 +0100

    Remove Rc<RefCell<T>> pattern in widgets::members_list

 fractal-gtk/src/widgets/members_list.rs | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/fractal-gtk/src/widgets/members_list.rs b/fractal-gtk/src/widgets/members_list.rs
index e6f9933d..0715fb90 100644
--- a/fractal-gtk/src/widgets/members_list.rs
+++ b/fractal-gtk/src/widgets/members_list.rs
@@ -1,10 +1,11 @@
 use glib::clone;
 use matrix_sdk::identifiers::UserId;
-use std::cell::RefCell;
 use std::collections::hash_map::HashMap;
-use std::rc::Rc;
 
-use glib::signal;
+use glib::{
+    signal::{self, SignalHandlerId},
+    translate::{FromGlib, ToGlib},
+};
 use gtk::prelude::*;
 
 use crate::model::member::Member;
@@ -69,14 +70,14 @@ impl MembersList {
                 Some(w.get_text().to_string()),
             );
         });
-        /* we need to remove the handler when the member list is destroyed */
-        let id: Rc<RefCell<Option<signal::SignalHandlerId>>> = Rc::new(RefCell::new(Some(id)));
+        // We need to remove the handler when the member list is destroyed
         let search_entry = self.search_entry.clone();
         self.container.connect_destroy(move |_| {
-            let id = id.borrow_mut().take();
-            if let Some(id) = id {
-                signal::signal_handler_disconnect(&search_entry, id);
-            }
+            signal::signal_handler_disconnect(
+                &search_entry,
+                // This type doesn't implement Clone nor Copy
+                SignalHandlerId::from_glib(id.to_glib()),
+            );
         });
         /* we could slowly load members when the main thread is idle */
         /*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]