From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 5F1021FF13C for ; Thu, 19 Feb 2026 15:57:49 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 59DFB192A5; Thu, 19 Feb 2026 15:57:27 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-ve-rs 5/9] ve-config: fabric: refactor fabric config entry impl using macro Date: Thu, 19 Feb 2026 15:56:24 +0100 Message-ID: <20260219145649.441418-8-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260219145649.441418-1-s.hanreich@proxmox.com> References: <20260219145649.441418-1-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.177 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 KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Message-ID-Hash: P2UH2AXH57QKUJNNUVRQPG2W4AICV5AJ X-Message-ID-Hash: P2UH2AXH57QKUJNNUVRQPG2W4AICV5AJ X-MailFrom: hoan@cray.proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Christoph Heiss 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 | 76 +++++++------------------ 1 file changed, 22 insertions(+), 54 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,66 +162,34 @@ 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; - } - - 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!(); - } -} +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; + } -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!(); + } - unreachable!(); - } + pub fn node_section( + &self, + id: &NodeId, + ) -> Result<&NodeSection<$nodepropty>, FabricConfigError> { + if let Node::$variant(section) = self.get_node(id)? { + return Ok(section); + } - /// 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!(); + } } - - unreachable!(); - } + }; } +impl_entry!(Openfabric, OpenfabricProperties, OpenfabricNodeProperties); +impl_entry!(Ospf, OspfProperties, OspfNodeProperties); + /// All possible entries in a [`FabricConfig`]. /// /// It utilizes the [`Entry`] struct to validate proper combinations of [`FabricSection`] and -- 2.47.3