[fractal] Get rid of option in some return types



commit 487509fdffe0ef1c3bdb56fd50e93191d956ffe5
Author: sonjita <sonjaleaheinze gmail com>
Date:   Thu Jan 2 15:16:17 2020 +0100

    Get rid of option in some return types
    
    Before some functions returned Option<T> even though T could be
    returned directly.

 fractal-gtk/src/appop/message.rs        |  8 ++++----
 fractal-gtk/src/widgets/message.rs      | 11 +++++------
 fractal-gtk/src/widgets/room_history.rs | 14 +++++++-------
 3 files changed, 16 insertions(+), 17 deletions(-)
---
diff --git a/fractal-gtk/src/appop/message.rs b/fractal-gtk/src/appop/message.rs
index 0f06f4a2..ad178b49 100644
--- a/fractal-gtk/src/appop/message.rs
+++ b/fractal-gtk/src/appop/message.rs
@@ -67,8 +67,8 @@ impl AppOp {
         let messages = self.history.as_ref()?.get_listbox();
         if let Some(ui_msg) = self.create_new_room_message(&msg) {
             let backend = self.backend.clone();
-            let mb = widgets::MessageBox::new(backend, login_data.server_url).tmpwidget(&ui_msg)?;
-            let m = mb.get_listbox_row()?;
+            let mb = widgets::MessageBox::new(backend, login_data.server_url).tmpwidget(&ui_msg);
+            let m = mb.get_listbox_row();
             messages.add(m);
 
             if let Some(w) = messages.get_children().iter().last() {
@@ -103,8 +103,8 @@ impl AppOp {
             if let Some(ui_msg) = self.create_new_room_message(&t.msg) {
                 let backend = self.backend.clone();
                 let mb = widgets::MessageBox::new(backend, login_data.server_url.clone())
-                    .tmpwidget(&ui_msg)?;
-                let m = mb.get_listbox_row()?;
+                    .tmpwidget(&ui_msg);
+                let m = mb.get_listbox_row();
                 messages.add(m);
 
                 if let Some(w) = messages.get_children().iter().last() {
diff --git a/fractal-gtk/src/widgets/message.rs b/fractal-gtk/src/widgets/message.rs
index 726350da..becb2909 100644
--- a/fractal-gtk/src/widgets/message.rs
+++ b/fractal-gtk/src/widgets/message.rs
@@ -93,18 +93,17 @@ impl MessageBox {
         self.connect_right_click_menu(msg, None);
     }
 
-    // FIXME: return directly row
-    pub fn get_listbox_row(&self) -> Option<&gtk::ListBoxRow> {
-        Some(&self.row)
+    pub fn get_listbox_row(&self) -> &gtk::ListBoxRow {
+        &self.row
     }
 
-    pub fn tmpwidget(mut self, msg: &Message) -> Option<MessageBox> {
+    pub fn tmpwidget(mut self, msg: &Message) -> MessageBox {
         self.create(msg, true);
         {
-            let w = self.get_listbox_row()?;
+            let w = self.get_listbox_row();
             w.get_style_context().add_class("msg-tmp");
         }
-        Some(self)
+        self
     }
 
     pub fn update_header(&mut self, msg: Message, has_header: bool) {
diff --git a/fractal-gtk/src/widgets/room_history.rs b/fractal-gtk/src/widgets/room_history.rs
index b4fe309b..8ab88ece 100644
--- a/fractal-gtk/src/widgets/room_history.rs
+++ b/fractal-gtk/src/widgets/room_history.rs
@@ -43,7 +43,7 @@ impl List {
         match element {
             Element::Message(ref message) => {
                 self.listbox
-                    .insert(message.widget.as_ref()?.get_listbox_row()?, 1);
+                    .insert(message.widget.as_ref()?.get_listbox_row(), 1);
             }
             Element::NewDivider(ref divider) => {
                 self.listbox.insert(divider.get_widget(), 1);
@@ -63,7 +63,7 @@ impl List {
         match element {
             Element::Message(ref message) => {
                 self.listbox
-                    .insert(message.widget.as_ref()?.get_listbox_row()?, -1);
+                    .insert(message.widget.as_ref()?.get_listbox_row(), -1);
             }
             Element::NewDivider(ref divider) => {
                 self.listbox.insert(divider.get_widget(), -1);
@@ -193,12 +193,12 @@ impl RoomHistory {
                         let divider = Element::NewDivider(create_new_message_divider());
                         rows.borrow_mut().add_top(divider);
                     }
-                    item.widget = create_row(
+                    item.widget = Some(create_row(
                         item.clone(),
                         has_header,
                         backend.clone(),
                         server_url.clone(),
-                    );
+                    ));
                     rows.borrow_mut().add_top(Element::Message(item));
                     if let Some(day_divider) = day_divider {
                         rows.borrow_mut().add_top(day_divider);
@@ -262,7 +262,7 @@ impl RoomHistory {
             self.backend.clone(),
             self.server_url.clone(),
         );
-        item.widget = b;
+        item.widget = Some(b);
         rows.add_bottom(Element::Message(item));
         None
     }
@@ -355,13 +355,13 @@ fn create_row(
     has_header: bool,
     backend: Sender<BKCommand>,
     server_url: Url,
-) -> Option<widgets::MessageBox> {
+) -> widgets::MessageBox {
     /* we need to create a message with the username, so that we don't have to pass
      * all information to the widget creating each row */
     let mut mb = widgets::MessageBox::new(backend, server_url);
     mb.create(&row, has_header && row.mtype != RowType::Emote);
 
-    Some(mb)
+    mb
 }
 
 /* returns if two messages should have only a single header or not */


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