From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 2A4371FF173 for ; Mon, 13 Jan 2025 12:16:03 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2F8442C86B; Mon, 13 Jan 2025 12:15:46 +0100 (CET) From: Shannon Sterz To: yew-devel@lists.proxmox.com Date: Mon, 13 Jan 2025 12:15:05 +0100 Message-Id: <20250113111505.160601-1-s.sterz@proxmox.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.083 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_SBL_A 0.1 Contains URL's A record listed in the Spamhaus SBL blocklist [185.199.109.153, 185.199.108.153, 185.199.111.153, 185.199.110.153] Subject: [yew-devel] [PATCH yew-widget-toolkit] tree-wide: use `?` instead of match statement where easily possible X-BeenThere: yew-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Yew framework devel list at Proxmox List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Yew framework devel list at Proxmox Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: yew-devel-bounces@lists.proxmox.com Sender: "yew-devel" 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 --- 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(node: T) -> Option { - 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 StoreState { 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 KeyedSlabTree { 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 KeyedSlabTree { } fn find_subnode_by_key(&self, node_id: usize, key: &Key) -> Option { - 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 DataNode for KeyedSlabTreeBorrowRef<'_, T> { self.tree.tree.root_id == Some(self.node_id) } fn parent(&self) -> Option + '_>> { - 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 PwtDataTable { fn find_focused_cell(&self) -> Option<(Key, Option)> { 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 PwtHeaderWidget { let get_cell_el = |cell_idx| -> Option { 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::() { 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 { - let menu_el = match self.inner_ref.cast::() { - Some(el) => el, - None => return None, - }; + let menu_el = self.inner_ref.cast::()?; 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 { - 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