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 8653D1FF13C for ; Thu, 02 Apr 2026 10:11:33 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 436EABC30; Thu, 2 Apr 2026 10:12:00 +0200 (CEST) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-ve-rs v2 05/25] ve-config: fabric: refactor fabric config entry impl using macro Date: Thu, 2 Apr 2026 10:11:25 +0200 Message-ID: <20260402081148.76276-6-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260402081148.76276-1-s.hanreich@proxmox.com> References: <20260402081148.76276-1-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1775117456612 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.704 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 Message-ID-Hash: FU723EJXWS3HAFVR4LAMQBHV4UGIVYSK X-Message-ID-Hash: FU723EJXWS3HAFVR4LAMQBHV4UGIVYSK X-MailFrom: s.hanreich@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