all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Shannon Sterz <s.sterz@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [yew-devel] [PATCH yew-widget-toolkit] tree-wide: use `?` instead of match statement where easily possible
Date: Mon, 13 Jan 2025 12:15:05 +0100	[thread overview]
Message-ID: <20250113111505.160601-1-s.sterz@proxmox.com> (raw)

this makes the code more concise and fixes the clippy lint
`question_mark` [1].

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#question_mark

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
---
 src/dom/mod.rs                          |  5 +----
 src/state/store.rs                      |  5 +----
 src/state/tree_store/keyed_slab_tree.rs | 10 ++--------
 src/state/tree_store/mod.rs             | 12 +++---------
 src/widget/data_table/data_table.rs     |  5 +----
 src/widget/data_table/header_widget.rs  |  5 +----
 src/widget/menu/mod.rs                  |  5 +----
 src/widget/theme_loader.rs              | 10 ++--------
 8 files changed, 12 insertions(+), 45 deletions(-)

diff --git a/src/dom/mod.rs b/src/dom/mod.rs
index 327a59f2..f61dd213 100644
--- a/src/dom/mod.rs
+++ b/src/dom/mod.rs
@@ -56,10 +56,7 @@ impl IntoHtmlElement for web_sys::HtmlElement {
 /// Uses `getComputedStyle()` to get the inherited CSS value. Simply returns
 /// [None] on error.
 pub fn element_direction_rtl<T: IntoHtmlElement>(node: T) -> Option<bool> {
-    let el = match node.into_html_element() {
-        Some(el) => el,
-        None => return None,
-    };
+    let el = node.into_html_element()?;
 
     let window = web_sys::window().unwrap();
     if let Ok(Some(style)) = window.get_computed_style(&el) {
diff --git a/src/state/store.rs b/src/state/store.rs
index e0ac683d..b068255a 100644
--- a/src/state/store.rs
+++ b/src/state/store.rs
@@ -497,10 +497,7 @@ impl<T: 'static> StoreState<T> {
             None => return None,
         };
 
-        let record = match self.data.get(n) {
-            Some(record) => record,
-            None => return None,
-        };
+        let record = self.data.get(n)?;
 
         Some(self.extract_key(record))
     }
diff --git a/src/state/tree_store/keyed_slab_tree.rs b/src/state/tree_store/keyed_slab_tree.rs
index 219a5362..b910beca 100644
--- a/src/state/tree_store/keyed_slab_tree.rs
+++ b/src/state/tree_store/keyed_slab_tree.rs
@@ -354,10 +354,7 @@ impl<T> KeyedSlabTree<T> {
             None => return None,
         };
 
-        let entry = match self.get(node_id) {
-            Some(entry) => entry,
-            None => return None,
-        };
+        let entry = self.get(node_id)?;
 
         Some(self.extract_key(&entry.record))
     }
@@ -469,10 +466,7 @@ impl<T> KeyedSlabTree<T> {
     }
 
     fn find_subnode_by_key(&self, node_id: usize, key: &Key) -> Option<usize> {
-        let entry = match self.get(node_id) {
-            Some(entry) => entry,
-            None => return None,
-        };
+        let entry = self.get(node_id)?;
 
         if key == &self.extract_key(&entry.record) {
             return Some(node_id);
diff --git a/src/state/tree_store/mod.rs b/src/state/tree_store/mod.rs
index 43264b0d..f583fd5b 100644
--- a/src/state/tree_store/mod.rs
+++ b/src/state/tree_store/mod.rs
@@ -374,15 +374,9 @@ impl<T> DataNode<T> for KeyedSlabTreeBorrowRef<'_, T> {
         self.tree.tree.root_id == Some(self.node_id)
     }
     fn parent(&self) -> Option<Box<dyn DataNode<T> + '_>> {
-        let entry = match self.tree.get(self.node_id) {
-            Some(entry) => entry,
-            None => return None,
-        };
-
-        let parent_id = match entry.parent_id {
-            Some(parent_id) => parent_id,
-            None => return None,
-        };
+        let entry = self.tree.get(self.node_id)?;
+
+        let parent_id = entry.parent_id?;
 
         let parent = Box::new(KeyedSlabTreeBorrowRef {
             node_id: parent_id,
diff --git a/src/widget/data_table/data_table.rs b/src/widget/data_table/data_table.rs
index aeca8bb9..8f664af7 100644
--- a/src/widget/data_table/data_table.rs
+++ b/src/widget/data_table/data_table.rs
@@ -858,10 +858,7 @@ impl<S: DataStore> PwtDataTable<S> {
     fn find_focused_cell(&self) -> Option<(Key, Option<usize>)> {
         let window = web_sys::window().unwrap();
         let document = window.document().unwrap();
-        let active_el = match document.active_element() {
-            Some(el) => el,
-            None => return None,
-        };
+        let active_el = document.active_element()?;
         dom_find_focus_pos(active_el, &self.unique_id)
     }
 
diff --git a/src/widget/data_table/header_widget.rs b/src/widget/data_table/header_widget.rs
index 2cf81acf..70bdf8b5 100644
--- a/src/widget/data_table/header_widget.rs
+++ b/src/widget/data_table/header_widget.rs
@@ -432,10 +432,7 @@ impl<T: 'static> PwtHeaderWidget<T> {
 
         let get_cell_el = |cell_idx| -> Option<web_sys::HtmlElement> {
             let id = self.unique_cell_id(cell_idx);
-            let el = match document.get_element_by_id(&id) {
-                Some(el) => el,
-                None => return None,
-            };
+            let el = document.get_element_by_id(&id)?;
             match el.dyn_into::<web_sys::HtmlElement>() {
                 Ok(el) => Some(el),
                 Err(_) => None,
diff --git a/src/widget/menu/mod.rs b/src/widget/menu/mod.rs
index 0c747134..0231430c 100644
--- a/src/widget/menu/mod.rs
+++ b/src/widget/menu/mod.rs
@@ -216,10 +216,7 @@ impl PwtMenu {
 
     // find the first focusable element inside an menu item
     fn get_focus_el(&self, cursor: usize) -> Option<web_sys::HtmlElement> {
-        let menu_el = match self.inner_ref.cast::<web_sys::Element>() {
-            Some(el) => el,
-            None => return None,
-        };
+        let menu_el = self.inner_ref.cast::<web_sys::Element>()?;
 
         let selector = format!(":scope > li[data-index='{}']", cursor);
         let item_el = match menu_el.query_selector(&selector) {
diff --git a/src/widget/theme_loader.rs b/src/widget/theme_loader.rs
index da9a8aad..f8a0d402 100644
--- a/src/widget/theme_loader.rs
+++ b/src/widget/theme_loader.rs
@@ -38,15 +38,9 @@ pub struct PwtThemeLoader {
 }
 
 fn get_document_root() -> Option<web_sys::Element> {
-    let window = match web_sys::window() {
-        Some(window) => window,
-        None => return None,
-    };
+    let window = web_sys::window()?;
 
-    let document = match window.document() {
-        Some(document) => document,
-        None => return None,
-    };
+    let document = window.document()?;
 
     document.document_element()
 }
-- 
2.39.5



_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel


             reply	other threads:[~2025-01-13 11:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-13 11:15 Shannon Sterz [this message]
2025-01-13 12:06 ` [yew-devel] applied: " Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250113111505.160601-1-s.sterz@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=yew-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal