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 6CC581FF141 for ; Fri, 16 Jan 2026 16:34:56 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 30C5D1C864; Fri, 16 Jan 2026 16:34:40 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Fri, 16 Jan 2026 16:33:15 +0100 Message-ID: <20260116153317.1146323-11-c.heiss@proxmox.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260116153317.1146323-1-c.heiss@proxmox.com> References: <20260116153317.1146323-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1768577597652 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.052 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox-ve-rs 10/11] ve-config: fabric: refactor fabric config entry impl using macro X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" It's always the same, so simplify future additions using a simple macro. Signed-off-by: Christoph Heiss --- proxmox-ve-config/src/sdn/fabric/mod.rs | 80 ++++++++----------------- 1 file changed, 24 insertions(+), 56 deletions(-) diff --git a/proxmox-ve-config/src/sdn/fabric/mod.rs b/proxmox-ve-config/src/sdn/fabric/mod.rs index 677a309..d0add92 100644 --- a/proxmox-ve-config/src/sdn/fabric/mod.rs +++ b/proxmox-ve-config/src/sdn/fabric/mod.rs @@ -162,65 +162,33 @@ where } } -impl Entry { - /// Get the OpenFabric fabric config. - /// - /// This method is implemented for [`Entry`], - /// so it is guaranteed that a [`FabricSection`] is returned. - pub fn fabric_section(&self) -> &FabricSection { - if let Fabric::Openfabric(section) = &self.fabric { - return section; +macro_rules! impl_entry { + ($variant:ident, $propty:ty, $nodepropty:ty) => { + impl Entry<$propty, $nodepropty> { + pub fn fabric_section(&self) -> &FabricSection<$propty> { + if let Fabric::$variant(section) = &self.fabric { + return section; + } + + unreachable!(); + } + + pub fn node_section( + &self, + id: &NodeId, + ) -> Result<&NodeSection<$nodepropty>, FabricConfigError> { + if let Node::$variant(section) = self.get_node(id)? { + return Ok(section); + } + + unreachable!(); + } } - - unreachable!(); - } - - /// Get the OpenFabric node config for the given node_id. - /// - /// This method is implemented for [`Entry`], - /// so it is guaranteed that a [`NodeSection`] is returned. - /// An error is returned if the node is not found. - pub fn node_section( - &self, - id: &NodeId, - ) -> Result<&NodeSection, FabricConfigError> { - if let Node::Openfabric(section) = self.get_node(id)? { - return Ok(section); - } - - unreachable!(); - } + }; } -impl Entry { - /// Get the OSPF fabric config. - /// - /// This method is implemented for [`Entry`], - /// so it is guaranteed that a [`FabricSection`] is returned. - pub fn fabric_section(&self) -> &FabricSection { - if let Fabric::Ospf(section) = &self.fabric { - return section; - } - - unreachable!(); - } - - /// Get the OSPF node config for the given node_id. - /// - /// This method is implemented for [`Entry`], - /// so it is guaranteed that a [`NodeSection`] is returned. - /// An error is returned if the node is not found. - pub fn node_section( - &self, - id: &NodeId, - ) -> Result<&NodeSection, FabricConfigError> { - if let Node::Ospf(section) = self.get_node(id)? { - return Ok(section); - } - - unreachable!(); - } -} +impl_entry!(Openfabric, OpenfabricProperties, OpenfabricNodeProperties); +impl_entry!(Ospf, OspfProperties, OspfNodeProperties); /// All possible entries in a [`FabricConfig`]. /// -- 2.52.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel